Extensible Stylesheet Language for Transformations XSLT An introduction
Why ‘transformations’? XML document XML document XML document HTML document XML document HTML document
Why ‘transformations’? XML document XML document HTML document Corpus search results More readable presentations
(1) Take an XML file… e.g., a play…. The Two Gentlemen of Verona Text placed in the public domain by Moby Lexical Tools, SGML markup by Jon Bosak, XML version by Jon Bosak, This work may be freely copied and distributed worldwide. Dramatis Personae DUKE OF MILAN, Father to Silvia. VALENTINE PROTEUS the two Gentlemen. …
(2) Take an XSLT file…
(2) Take an XSLT file… From the top of an XML file(“/”), go looking for any place where we can find a TITLE element (“//TITLE”). XPath
(2) Take an XSLT file… Whenever we find a TITLE element (“TITLE”), take the value of that ‘node’ (“.”) and put it in our output document
… (3) apply the XSLT file to the XML file of the play …
(4) And hey presto…. … all the TITLES from the play…
… that is not very readable though, so we can …
(5) … add some HTML
(5) … add some HTML
(5) … add some HTML Search Results
(5) … add some HTML Search Results HTML
… (6) apply the XSLT file to the XML file of the play again…
… and we get …
We can also start making it fancier… Search Results Our search results This time we wrap the HTML code for a table around our XSLT expressions…
… (7) apply the XSLT file to the XML file of the play again …
… and we get …
Lets make this more useful… Task: select all the lines in the play that were spoken by some particular character…
How do we do this? Look in the XML file to see how speaker turns are represented Write a proper XPath expression to pick out just the turns that we are interested in Put that XPath expression in place of our “TITLE” XPath in the example XSLT file Apply the XSLT file to the play again
The DTD gives us the kinds of XPath expressions that we need /PLAY
The DTD gives us the kinds of XPath expressions that we need /PLAY /ACT
The DTD gives us the kinds of XPath expressions that we need /PLAY /ACT/SCENE
The DTD gives us the kinds of XPath expressions that we need /PLAY /ACT/SCENE/SPEECH
The DTD gives us the kinds of XPath expressions that we need /PLAY /ACT/SCENE/SPEECH
Try #1 Search Results Our search results
Result #1
Try #2
Result #2
A variant of Try #2
Try #3
Result #3
As final icing on the cake… Lets replace the redundant name with the title of the scene that the turns occur in!
A solution…
And one more complex example still… The turns of SPEED plus the preceding turn to show the dialogue context… The stylesheet is on the course website
There is very little one cannot do with an XSLT for transforming documents Although it can be quite difficult sometimes to see how!