Extensible Stylesheet Language for Transformations XSLT An introduction.

  • Published on
    14-Dec-2015

  • View
    212

  • Download
    0

Transcript

Slide 1Extensible Stylesheet Language for Transformations XSLT An introduction Slide 2 Why transformations? XML document XML document XML document HTML document XML document HTML document Slide 3 Why transformations? XML document XML document HTML document Corpus search results More readable presentations Slide 4 (1) Take an XML file e.g., a play. The Two Gentlemen of Verona Text placed in the public domain by Moby Lexical Tools, 1992. SGML markup by Jon Bosak, 1992-1994. XML version by Jon Bosak, 1996-1998. This work may be freely copied and distributed worldwide. Dramatis Personae DUKE OF MILAN, Father to Silvia. VALENTINE PROTEUS the two Gentlemen. Slide 5 Slide 6 Slide 7 Slide 8 (2) Take an XSLT file http://www.w3.org/1999/XSL/Transform Slide 9 (2) Take an XSLT file http://www.w3.org/1999/XSL/Transform From the top of an XML file(/), go looking for any place where we can find a TITLE element (//TITLE). XPath Slide 10 (2) Take an XSLT file http://www.w3.org/1999/XSL/Transform Whenever we find a TITLE element (TITLE), take the value of that node (.) and put it in our output document Slide 11 (3) apply the XSLT file to the XML file of the play Slide 12 (4) And hey presto. all the TITLES from the play Slide 13 that is not very readable though, so we can Slide 14 (5) add some HTML Slide 15 (5) add some HTML Slide 16 (5) add some HTML Search Results Slide 17 (5) add some HTML Search Results HTML Slide 18 (6) apply the XSLT file to the XML file of the play again Slide 19 and we get Slide 20 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 Slide 21 (7) apply the XSLT file to the XML file of the play again Slide 22 and we get Slide 23 Lets make this more useful Task: select all the lines in the play that were spoken by some particular character Slide 24 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 Slide 25 The DTD gives us the kinds of XPath expressions that we need /PLAY Slide 26 The DTD gives us the kinds of XPath expressions that we need /PLAY /ACT Slide 27 The DTD gives us the kinds of XPath expressions that we need /PLAY /ACT/SCENE Slide 28 The DTD gives us the kinds of XPath expressions that we need /PLAY /ACT/SCENE/SPEECH Slide 29 The DTD gives us the kinds of XPath expressions that we need /PLAY /ACT/SCENE/SPEECH Slide 30 Try #1 Search Results Our search results Slide 31 Result #1 Slide 32 Slide 33 Try #2 Slide 34 Result #2 Slide 35 Slide 36 A variant of Try #2 Slide 37 Try #3 Slide 38 Result #3 Slide 39 Slide 40 As final icing on the cake Lets replace the redundant name with the title of the scene that the turns occur in! Slide 41 A solution Slide 42 Slide 43 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 Slide 44 Slide 45 There is very little one cannot do with an XSLT for transforming documents Although it can be quite difficult sometimes to see how!

Recommended

View more >