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

Post on 21-Dec-2015

228 views 1 download

Tags:

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

XSLTXSLT

Susanne SherbaSusanne Sherba

October 12, 2000October 12, 2000

OverviewOverview

• What is XSLT?What is XSLT?

• Related RecommendationsRelated Recommendations

• XSLT ElementsXSLT Elements

• Associating Stylesheets with Associating Stylesheets with DocumentsDocuments

• Additional InformationAdditional Information

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]

XSLT ProcessXSLT Process

XSLT StatusXSLT Status

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

• Version 1.0Version 1.0

Related Related RecommendationsRecommendations

• XPathXPath

• XSLXSL

• XML Stylesheet RecommendationXML Stylesheet Recommendation

XSLT Stylesheet ElementXSLT Stylesheet Element

<stylesheet version = “1.0”>

<transform> allowed as synonym

XSLT Template ElementXSLT Template Element

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

Applying TemplatesApplying Templates

<apply-templatesselect = expression mode = name>

<call-template name = name>

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

Example 1Example 1

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

Example 2Example 2

RepetitionRepetition

<for-eachselect = “item”>

Do something here ...

</for-each>

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

Example 3Example 3

Conditional ProcessingConditional Processing

<if

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

Do something …

</if>

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>

Creating the result treeCreating the result tree

<value-of select=expression>

<element name=string>

<attribute name=string>

<processing-instruction name=string>

<comment>

<text>

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

NumberingNumbering

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

Combining StylesheetsCombining Stylesheets

<include href = uri />

<import href = uri />

Some Other ElementsSome Other Elements

<copy>

<copy-of>

<sort select=“expression”>

<variable>

<param>

<output>

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

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