1 / 25

XSLT

XSLT. Susanne Sherba. October 12, 2000. Overview. What is XSLT? Related Recommendations XSLT Elements Associating Stylesheets with Documents Additional Information. What is XSLT?. A language for transforming XML documents into other XML documents

palani
Télécharger la présentation

XSLT

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. XSLT Susanne Sherba October 12, 2000

  2. Overview • What is XSLT? • Related Recommendations • XSLT Elements • Associating Stylesheets with Documents • Additional Information

  3. What is XSLT? • A language for transforming XML documents into other XML documents • Designed for use both as part of XSL and independently of XSL • Not intended as a completely general-purpose XML transformation language. [W3C XSLT Recommendation]

  4. XSLT Process

  5. XSLT Status • W3C Recommendation - November 16, 1999 • Version 1.0

  6. Related Recommendations • XPath • XSL • XML Stylesheet Recommendation

  7. XSLT Stylesheet Element <stylesheet version= “1.0”> <transform> allowed as synonym

  8. XSLT Template Element <templatematch = expressionname = namepriority = numbermode = name>

  9. Applying Templates <apply-templatesselect = expressionmode = name> <call-template name = name>

  10. Example 1 <?xml version="1.0"?> <?xml-stylesheet href="style1.xsl” type="text/xsl"?> <items> <item partNum="123-AB"> <productName>Porsche</productName> <quantity>1</quantity> </item> <item> <productName>Ferrari</productName> <quantity>2</quantity> </item> </items> <?xml version="1.0"?> <xsl:stylesheet version=“1.0” xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <head></head> <body> <ol> <li>Root</li> <xsl:apply-templates/> </ol> </body> </html> </xsl:template> <xsl:template match="items"> <li>Items</li> <xsl:apply-templates/> </xsl:template> <xsl:template match="item"> <li>Item: <xsl:value-of select="productName"/></li> </xsl:template> </xsl:stylesheet>

  11. Example 1

  12. Example 2 <?xml version="1.0"?> <?xml-stylesheet href="style2.xsl” type="text/xsl"?> <items> <item partNum="123-AB"> <productName>Porsche</productName> <quantity>1</quantity> </item> <item> <productName>Ferrari</productName> <quantity>2</quantity> </item> </items> <?xml version="1.0"?> <xsl:stylesheet version=“1.0” xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <head></head> <body> <ol> <xsl:apply-templates/> <li>Root</li> </ol> </body> </html> </xsl:template> <xsl:template match="items"> <xsl:apply-templates/> <li>Items</li> </xsl:template> <xsl:template match="item"> <li>Item: <xsl:value-of select="productName"/></li> </xsl:template> </xsl:stylesheet>

  13. Example 2

  14. Repetition <for-eachselect = “item”> Do something here ... </for-each>

  15. Example 3 <?xml version="1.0"?> <?xml-stylesheet href="style3.xsl” type="text/xsl"?> <items> <item partNum="123-AB"> <productName>Porsche</productName> <quantity>1</quantity> </item> <item> <productName>Ferrari</productName> <quantity>2</quantity> </item> </items> <?xml version="1.0"?> <xsl:stylesheet version=“1.0” xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <head></head> <body> <ol> <li>Root</li> <xsl:apply-templates/> </ol> </body> </html> </xsl:template> <xsl:template match="items"> <li>Items</li> <xsl:for-each select="item"> <li>Item: <xsl:value-of select="productName"/> </li> </xsl:for-each> </xsl:template> </xsl:stylesheet>

  16. Example 3

  17. Conditional Processing <if test = “position()=last()”> Do something … </if>

  18. Conditional Processing <choose> <whentest = “position()=last()”> Do something for last element </when> <whentest = “position()=first()”> Do something for first element </when> <otherwise> Do something for other elements </otherwise> </choose>

  19. Creating the result tree <value-of select=expression> <element name=string> <attribute name=string> <processing-instruction name=string> <comment> <text>

  20. Example 4 <xsl:template match="/"> <html> <head></head> <xsl:comment> Set the background to red </xsl:comment> <xsl:element name="body"> <xsl:attribute name="bgcolor"> red </xsl:attribute> <ol> <li>Root</li> <xsl:apply-templates/> </ol> </xsl:element> </html> </xsl:template> ... XSL output: <html><head></head><!--Set the background to red--><body bgcolor="red"><ol><li>Root</li><li>Items</li><li>Item: Porsche</li><li>Item: Ferrari</li></ol></body></html>

  21. Numbering <numbercount = patternfrom = patternvalue = number-expressionformat = string/>

  22. Combining Stylesheets <include href = uri /> <import href = uri />

  23. Some Other Elements <copy> <copy-of> <sort select=“expression”> <variable> <param> <output>

  24. Associating Stylesheets with Documents W3C Stylesheets Recommendation Version 1.0 In the xml document: <?xml-stylesheet href=uri type=“text/xsl”?>

  25. Additional Information • XSLT Recommendation Version 1.0 - http://www.w3.org/TR/xslt • XSLT.com - http://www.xslt.com • XSLT Reference - http://www.zvon.org/xxl/XSLTreference/Output/index.html

More Related