XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related...

25
XSLT XSLT Susanne Sherba Susanne Sherba October 12, 2000 October 12, 2000
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    228
  • download

    1

Transcript of XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related...

Page 1: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

XSLTXSLT

Susanne SherbaSusanne Sherba

October 12, 2000October 12, 2000

Page 2: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

OverviewOverview

• What is XSLT?What is XSLT?

• Related RecommendationsRelated Recommendations

• XSLT ElementsXSLT Elements

• Associating Stylesheets with Associating Stylesheets with DocumentsDocuments

• Additional InformationAdditional Information

Page 3: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

What is XSLT?What is XSLT?

• A language for transforming XML A language for transforming XML documents into other XML documentsdocuments into other XML documents

• Designed for use both as part of XSL Designed for use both as part of XSL and independently of XSLand independently of XSL

• Not intended as a completely general-Not intended as a completely general-purpose XML transformation language.purpose XML transformation language.

[W3C XSLT Recommendation][W3C XSLT Recommendation]

Page 4: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

XSLT ProcessXSLT Process

Page 5: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

XSLT StatusXSLT Status

• W3C Recommendation - November W3C Recommendation - November 16, 199916, 1999

• Version 1.0Version 1.0

Page 6: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Related Related RecommendationsRecommendations

• XPathXPath

• XSLXSL

• XML Stylesheet RecommendationXML Stylesheet Recommendation

Page 7: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

XSLT Stylesheet ElementXSLT Stylesheet Element

<stylesheet version = “1.0”>

<transform> allowed as synonym

Page 8: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

XSLT Template ElementXSLT Template Element

<templatematch = expression name = name priority = number mode = name>

Page 9: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Applying TemplatesApplying Templates

<apply-templatesselect = expression mode = name>

<call-template name = name>

Page 10: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

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

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

Example 1Example 1

Page 11: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Example 1Example 1

Page 12: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

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

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

Example 2Example 2

Page 13: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Example 2Example 2

Page 14: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

RepetitionRepetition

<for-eachselect = “item”>

Do something here ...

</for-each>

Page 15: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

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

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

Example 3Example 3

Page 16: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Example 3Example 3

Page 17: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Conditional ProcessingConditional Processing

<if

test = “position()=last()”>

Do something …

</if>

Page 18: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Conditional ProcessingConditional Processing<choose>

<when test = “position()=last()”> Do something for last element

</when>

<when test = “position()=first()”> Do something for first element

</when>

<otherwise>

Do something for other elements

</otherwise>

</choose>

Page 19: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Creating the result treeCreating the result tree

<value-of select=expression>

<element name=string>

<attribute name=string>

<processing-instruction name=string>

<comment>

<text>

Page 20: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

XSL output: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>

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

Example 4Example 4

Page 21: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

NumberingNumbering

<numbercount = pattern from = pattern value = number-expression format = string/>

Page 22: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Combining StylesheetsCombining Stylesheets

<include href = uri />

<import href = uri />

Page 23: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Some Other ElementsSome Other Elements

<copy>

<copy-of>

<sort select=“expression”>

<variable>

<param>

<output>

Page 24: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Associating Stylesheets Associating Stylesheets with Documentswith Documents

W3C Stylesheets Recommendation W3C Stylesheets Recommendation Version 1.0Version 1.0

In the xml document:In the xml document:

<?xml-stylesheet href=uri type=“text/xsl”?>

Page 25: XSLT Susanne Sherba October 12, 2000. Overview What is XSLT?What is XSLT? Related RecommendationsRelated Recommendations XSLT ElementsXSLT Elements Associating.

Additional InformationAdditional Information

• XSLT Recommendation Version 1.0 - XSLT Recommendation Version 1.0 - http://www.w3.org/TR/xslthttp://www.w3.org/TR/xslt

• XSLT.com - XSLT.com - http://www.xslt.comhttp://www.xslt.com

• XSLT Reference - XSLT Reference - http://www.zvon.org/xxl/XSLTreferehttp://www.zvon.org/xxl/XSLTreference/Output/index.htmlnce/Output/index.html