1 / 12

CIS 375—Web App Dev II

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)

kemal
Download Presentation

CIS 375—Web App Dev II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 375—Web App Dev II XSL

  2. 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)

  3. 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.

  4. 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

  5. <?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)

  6. 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>

  7. 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

  8. 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.

  9. 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 !=, &lt;,&gt; operators). • If you have Netscape 6 or IE 5 or higher you can view: the XML file and the XSL file, and the result.

  10. 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.

  11. The <xsl:if> Element • A conditional if test: <xsl:for-each select="catalog/cd"> <xsl:if test="price&gt;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.

  12. 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&gt;'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.

More Related