120 likes | 433 Views
XSL. eXtensible Style Language. greeting.xml. <?xml version="1.0" standalone="yes"?> <GREETING> Hello XML! </GREETING>. greeting.xsl. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <body> <h1>
E N D
XSL • eXtensible Style Language
greeting.xml • <?xml version="1.0" standalone="yes"?> • <GREETING> • Hello XML! • </GREETING>
greeting.xsl • <?xml version="1.0"?> • <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> • <xsl:template match="/"> • <html> • <body> • <h1> • <xsl:value-of select="GREETING"/> • </h1> • </body> • </html> • </xsl:template> • </xsl:stylesheet>
Attaching a style sheet to an XML document • xml-stylesheet processing instruction after the XML declaration and before the root element • type attribute has the value text/css or text/xsl • href attribute is a URL to the stylesheet, possibly relative
The Extensible Style Language • Partially supported by IE 5.0 • Many third party tools • W3C Working Draft
The Two Parts of XSL • Transformation Language • Formatting Objects
Templates <HTML> <HEAD> <TITLE> XSL Instructions to get the title </TITLE> </HEAD> <H1>XSL Instructions to get the title</H1> <BODY> XSL Instructions to get the statistics </BODY> </HTML>
XSL Instructions • An XSL style sheet is a well-formed XML document • XSL instructions are particular XML elements • xsl:apply-templates • xsl:template • xsl:for-each • xsl:value-of • a few others
An XSL style sheet • <?xml version="1.0"?> • <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> • <xsl:template match="/"> • <HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl"> • <HEAD><TITLE> • Major League Baseball Statistics • </TITLE></HEAD> • <BODY> • <H1>Major League Baseball Statistics</H1> • </BODY></HTML> • </xsl:template> • </xsl:stylesheet>
xsl:for-each and xsl:value-of • <xsl:template match="/"> • <HTML • xmlns:xsl="http://www.w3.org/TR/WD-xsl"> • <HEAD><TITLE> • <xsl:for-each select="SEASON"> • <xsl:value-of select="@YEAR"/> • </xsl:for-each> • Major League Baseball Statistics • </TITLE></HEAD> • <BODY> • <xsl:for-each select="SEASON"> • <H1><xsl:value-of select="@YEAR"/> • Major League Baseball Statistics</H1> • </xsl:for-each> • </BODY></HTML> • </xsl:template>
xsl:for-each and xsl:value-of <xsl:for-each select="SEASON"> <xsl:value-of select="@YEAR"/> </xsl:for-each>
CSS or XSL? • CSS has broader support • CSS is more stable • XSL is more powerful