120 likes | 213 Views
CIS 375—Web App Dev II. XSL. XSL Introduction. XSL stands for _____________________________. XSL is the language used for manipulating and displaying the contents of _____ documents. XSL is a W3C standard. XSL consists of three parts: XSLT (a language for transforming XML documents)
E N D
XSL Introduction • XSL stands for _____________________________. • XSL is the language used for manipulating and displaying the contents of _____ documents. • XSL is a W3C standard. • XSL consists of three parts: • XSLT (a language for transforming XML documents) • XPath (a language for defining parts of an XML document) • XSL Formatting Objects (a vocabulary for formatting XML documents)
XSL Languages • A browser doesn’t understand the unique elements of an XML document. • XSL-Transformation (XSLT) is a language for transforming XML documents into those understood by a browser, such as ________. • XSLT can also • rearrange and sort elements • test and make decisions about which elements to display • and a lot more • XSLT transforms an XML _______ tree into an XML _______ tree using XPath.
XSL-Transformation • IE 6 is fully compliant with W3C’s XSL Standard. • The correct way to declare an XSL style sheet : <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> • An XML __________ (xmlns) is a way to guarantee the uniqueness of element and attribute names. • You can also use the term “____________” instead of “stylesheet” above. • To apply a style sheet • start with the XML document • create an XSL document • link the XML document to the XSL document • view the XML document in a browser
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th align="left">Title</th> <th align="left">Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> XSL Stylesheet (cdcatalog.xsl)
Linking XML and XSL • To link an XML document to an XSL stylesheet: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> . . . </catalog>
The <xsl:template> Element • The stylesheet is an _____ document, hence <?xml version="1.0" encoding="ISO-8859-1"?> • The <xsl:stylesheet> tag defines the start of the style sheet. • The <xsl:template> tag defines the start of a template. • The match="/" attribute matches the template to the ______ of the XML source document. • If you have Netscape 6 or IE 5 or higher you can view: the XML file, the XSL file, and the result
The <xsl:value-of> Element • The <xsl:value-of> element selects the value of an XML element for displaying. • The value of the required select attribute contains an _______ expression. • For example , if <xsl:template match="/">, then <xsl:value-of select="catalog/cd/title"/> • If you have Netscape 6 or IE 5 or higher you can view the XML file and the XSL file, and the result.
The <xsl:for-each> Element • The XSL <xsl:for-each> element can be used to select every XML element of a specified ______ set. • For example, if <xsl:for-each select="catalog/cd"> then you can write <xsl:value-of select="title"/> • To ________ the output <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> (also use !=, <,> operators). • If you have Netscape 6 or IE 5 or higher you can view: the XML file and the XSL file, and the result.
The <xsl:sort> Element • The following code allows you to sort the output: <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> • If you have Netscape 6 or IE 5 or higher you can view: the XML file and the XSL file, and the result.
The <xsl:if> Element • A conditional if test: <xsl:for-each select="catalog/cd"> <xsl:if test="price>10"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:if> </xsl:for-each> • If you have Netscape 6 or IE 5 or higher you can view: the XML file and the XSL file, and the result.
The <xsl:choose> Element • For doing alternative processing, <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <xsl:choose> <xsl:when test="price>'10'"> <td bgcolor="#ff00ff"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="artist"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> • If you have Netscape 6 or IE 5 or higher you can view: the XML file and the XSL file, and the result.