JavaScript Transforming XML to HTML on the fly, and adding JavaScript events?

I'm running a Django site with XML text stored in TextField properties. It's stored as XML rather than plain text because it's heavily annotated with information about the underlying manuscript, such as abbreviations and symbols. Here's an example:

class Entry(models.Model):
  # Name and description. 
  chapter = models.ForeignKey(Chapter)
  latin_text = models.TextField()

Here's an example of the content of latin_text:

<initial type="2">I</initial>n <place type="0"><span>Ricmond</span></place> 
ten<abbr type="1">et</abbr> aeccl<abbr type="0">esi</abbr>a
de Cietriz .ii. hid<abbr type="0">as</abbr>. 

I'd now like to start displaying that XML text on my HTML pages.

I know I can display raw XML by dropping it into a textarea: the issue is that I'd like to display it in a more beautiful way, with:

  • styling (all the abbr elements in italics, the place element in bold)
  • JavaScript events to let the user explore the abbreviations (when the user mouses over an abbr or place, show a pop-up explanation)

I'm not sure if XSLT can do what I need, or even if it can be used alongside HTML. So my question is:

  • Should I transform the XML into HTML before adding it to the Django database?
  • Or can I do all the rendering I need on the fly with XSLT or JavaScript?
Answer:1

I would use xslt to transform it and then attach events programmatically with javascript. It is data and converting it before hand prevents you then interpreting it in a different way later. Html should be layout only and separate from the data. You could translate it with Javascript but that will be intensive on the client. Xslt and css will be cleaner and attaching events in js is lightweight.

Not familiar with Django but maybe check this answer out : Can I use XSLT in Django?

Answer:2

HTML: <script>function dropdown() { console.getElementById("").style.display="block"; }</script> <div id="dropdown"> <ul> <li onclick="dropdown()"><...

HTML: <script>function dropdown() { console.getElementById("").style.display="block"; }</script> <div id="dropdown"> <ul> <li onclick="dropdown()"><...

  1. using onclick event in javascript
  2. onclick with event
  3. using jquery in onclick event

I was using a for loop to conditionally iterate over HTML input and concatenate a pipe separated string. Because I didn't want an ending pipe character I used foo.slice(0, -1). It occurred to me that ...

I was using a for loop to conditionally iterate over HTML input and concatenate a pipe separated string. Because I didn't want an ending pipe character I used foo.slice(0, -1). It occurred to me that ...

  1. javascript empty string falsey
  2. javascript empty string truthy
  3. javascript empty string check
  4. javascript empty string vs null
  5. javascript empty string if null
  6. javascript empty string constant
  7. javascript empty string array
  8. javascript empty string is false
  9. javascript empty string to 0
  10. javascript empty string equals null
  11. javascript empty string regex
  12. javascript empty string to null
  13. javascript empty string is undefined
  14. javascript empty string boolean value
  15. javascript empty string to number
  16. javascript empty string vs undefined
  17. javascript empty string instead of undefined
  18. javascript empty string object key
  19. javascript empty string object
  20. javascript empty string validation

I'm writing some simple code to change the visibility of an image when a button is clicked, but my document.getElementById().value is coming up as undefined. (I've tried replacing .value with .display ...

I'm writing some simple code to change the visibility of an image when a button is clicked, but my document.getElementById().value is coming up as undefined. (I've tried replacing .value with .display ...

  1. getelementbyid not returning value

I want to move items between two Listboxes in ASP.Net using JQuery/Javascript and below is my code which is working perfectly. function AddItems() { var totalItemsSelected = 0; var ...

I want to move items between two Listboxes in ASP.Net using JQuery/Javascript and below is my code which is working perfectly. function AddItems() { var totalItemsSelected = 0; var ...

  1. move items between sharepoint lists
  2. move items between vaults 1password
  3. move items between characters destiny 2
  4. move items between two select lists
  5. move items between calendars in outlook
  6. move items between layers indesign
  7. move items between two listbox c#
  8. move items between settlements fallout 4
  9. move items between listboxes c#
  10. move items between listboxes vba
  11. move items between listboxes
  12. move items between two listboxes javascript
  13. move items between folders in sharepoint
  14. move items between keychains
  15. move items between two select lists bootstrap
  16. move items between lists angular
  17. move items between list view javafx
  18. zotero move items between collections
  19. rimworld move items between stockpiles
  20. bdo move items between characters