digital media technology week 6. xml source xslt stylesheet xml result xslt
TRANSCRIPT
![Page 1: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/1.jpg)
Digital Media Technology
Week 6
![Page 2: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/2.jpg)
XML Source
XSLT Stylesheet
XML Result
XSLT
![Page 3: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/3.jpg)
Tree diagram of an XSLT stylesheet
![Page 4: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/4.jpg)
<xsl:stylesheet>
</xsl:stylesheet>
<xsl:template match=“collection” >
</xsl:template>
<xsl:template match=“letter” >
</xsl:template>
![Page 5: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/5.jpg)
Example: XML source
<?xml version="1.0" encoding="UTF-8"?><letter> <head>Letter from De Erven F. Bohn to W. Blackwood and sons, January 22nd, 1873</head> <body> <dateline> <place>Haarlem</place> <date>22 January 1873</date> </dateline> <greeting>Dear Sirs!</greeting> <p>We beg to apply to you the kind request for sending us one week before the publication one copy of Bulwer's novel: <title>Kenelm Chillingly, His adventures and opinions</title>, which book you have in the press, for what we are inclined to pay 30 £. When it were possible to send us already now the first volume by the post; it would be yet more agreeable. Mr H.A. Kramers at Rotterdam readily will be our pledge.</p> <salute> your truly</salute> <signed>De Erven F. Bohn</signed> </body></letter>
![Page 6: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/6.jpg)
□ Include a template that points to the root element of the XML source.
Getting started
<?xml version="1.0" encoding="UTF-8"?><letter> <head>Letter from De Erven F. Bohn to W. Blackwood and sons, January 22nd, 1873</head><body>….</body></letter>
![Page 7: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/7.jpg)
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="letter">
</xsl:template> </xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<letter>
…
</letter>
XML Source
XSLT
XML Result
![Page 8: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/8.jpg)
□ Literal text can be added with the <xsl:text>element.e.g.<xsl:text>This sentence will be visible in the result.</xsl:text>
□ HTML tags may be added directlye.g.<i><xsl:text>This text will be italicised<xsl:text></i>
Elements within <xsl:template>
![Page 9: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/9.jpg)
□ Use <xsl:value-of> to select text from the XML source.e.g.<xsl:value-of select=“head”/><xsl:value-of select=“body/dateline”/>
□ Note that the paths in the select-attribute must depart from the element mentioned in the match-attribute of <xsl:template>
Elements within <xsl:template>
![Page 10: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/10.jpg)
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match=“letter"> <html> <head>
<title> <xsl:text>XSLT transformation</xsl:text></title>
</head> <body> <h2>
<xsl:value-of select=“head”></h2>
</body> </html> </xsl:template> </xsl:stylesheet>
XSLT stylesheet
![Page 11: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/11.jpg)
Exercise 1
![Page 12: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/12.jpg)
Example: XML source
<?xml version="1.0" encoding="UTF-8"?><EU> <country> <name> Belgium </name> <capital>Brussels</capital> </country> <country> <name>Cyprus </name> <capital>Nicosia</capital> </country> <country> <name>Denmark </name> <capital>Copenhagen</capital> </country> …</EU>
![Page 13: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/13.jpg)
XSLT stylesheet
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="EU"> <ul><li> <xsl:text>The capital of </xsl:text> <xsl:value-of select="country/name"/> <xsl:text> is </xsl:text> <xsl:value-of select="country/capital"/> <xsl:text>.</xsl:text> </li></ul> </xsl:template> </xsl:stylesheet>
![Page 14: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/14.jpg)
□ <xsl:for-each> needs to be used if all the elements on a certain level need to be shown.
□ This XSLT element takes a select-attribute
□ Note that the paths within <xsl:for-each> must depart from the element that is mentioned mentioned in the select-attribute.
![Page 15: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/15.jpg)
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="EU"> <ul> <xsl:for-each select="country"> <li> <xsl:text>The capital of </xsl:text> <xsl:value-of select="name"/> <xsl:text> is </xsl:text> <xsl:value-of select="capital"/> <xsl:text>.</xsl:text> </li> </xsl:for-each> </ul> </xsl:template> </xsl:stylesheet>
XSLT stylesheet
![Page 16: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/16.jpg)
Exercise 2
![Page 17: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/17.jpg)
□ Use <xsl:sort> to sort a list alphabeticaly or numerically
□ This XSLT element also takes a select-attribute. It refers to the element the XSLT processor must sort by
□ <xsl:sort> must be the direct child of <xsl:for-each> (or <xsl:apply-templates>)
<xsl:sort>
![Page 18: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/18.jpg)
Exercise 3
![Page 19: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/19.jpg)
□ <xsl:if> takes a “test” attribute
□ The instructions within <xsl:if> will only be carried out if the criterion in the test attribute can be evaluated as true
□ Example:
<xsl:if test=“date”><xsl:value=“date”/>
</xsl:if>
<xsl:if>
![Page 20: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/20.jpg)
Exercise 4
![Page 21: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/21.jpg)
□ The items that will be selected within the <xsl:for-each> loop can be filtered by adding a criterion within square brackets, directly after the element name.
□ Operators that can be used to formulate such tests:
= Equal to
!= Not equal to
< Less than
> Greater than
![Page 22: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/22.jpg)
Exercise 5
![Page 23: Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT](https://reader030.vdocuments.mx/reader030/viewer/2022032709/56649eaa5503460f94baf93b/html5/thumbnails/23.jpg)
□ <xsl:value-of>□ <xsl:text>□ <xsl:for-each>□ <xsl:sort>□ <xsl:if>
Elements within <xsl:template>