only for RuBoard |
xsl:apply-templates recursively processes the children of the source element.
Template rules are defined using xsl:template , imported using xsl:import , or included using xsl:include . If the select attribute is specified, a node list is generated that is applied to the rest of the stylesheet. If the select attribute is missing, all children of the current element are used in the resulting node list. Each node is then tested against the templates to see if it applies to the definition of the template rule, following the recommendation for conflict resolution for template rules (defined in the W3C recommendation, Section 5.5, at www.w3.org/TR/xslt).
Both xsl:template and xsl:apply-templates have an optional mode attribute. The value of the mode attribute is a QName . If xsl:template does not have a match attribute, it must not have a mode attribute. If an xsl:apply-tem plates element has a mode attribute, it applies only to those template rules from xsl:template elements that have a mode attribute with the same value; if an xsl:apply-templates element does not have a mode attribute, it applies only to those template rules from xsl:template elements that do not have a mode attribute.
Attribute Name | Enforced | Description | Values |
---|---|---|---|
select | Optional | Specifies the node list to return | An expression returning a node set |
mode | Optional | Allows an element to be processed multiple times, each time returning a different result | QName |
Suppose that you have a series of links that you want to display on a page. Each link is represented here by a link element with properties for its unique identifier, its location on the web, a memorable name for the link, and a brief description of the site:
<?xml version="1.0" encoding="utf-8" ?> <links> <link id="newriders" URL="http://www.newriders.com" name="NewRiders.com" description="Available books by New Riders" /> <link id="/xmlandasp" URL="http://www.xmlandasp.net" name="Xmlandasp.net" description="Articles and samples available for VB, DNA, and .NET" /> <link id="gotdotnet" URL="http://www.gotdotnet.com" name="GotDotNet.com" description="Samples, walkthroughs, and more" /> <link id="msdn" URL="http://msdn.microsoft.com/library" name="MSDN Online Library" description="MSDN Online" /> <link id="devx" URL="http://www.devx.com" name="DevX.com" description="Fawcette Technical Publications" /> </links>
The stylesheet doc.xsl contains template rules to process each link element twice ”once to generate an index of links, and the second to generate the named anchor tag, its URL, name, and description. Notice that the character entity reference # for t he hash ( # ) symbol is used because the pound symbol has meaning in XSLT.
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <xsl:apply-templates select="links/link" /> <hr /> <xsl:apply-templates select="links/link" mode="description" /> </body> </html> </xsl:template> <xsl:template match="link"> <a> <xsl:attribute name="href"> #<xsl:value-of select="@id" /> </xsl:attribute> <xsl:value-of select="@name" /> </a> <br /> </xsl:template> <xsl:template match="link" mode="description"> <a> <xsl:attribute name="name"> <xsl:value-of select="@id" /> </xsl:attribute> <h1> <xsl:value-of select="@name" /> </h1> </a> <a> <xsl:attribute name="href"> <xsl:value-of select="@URL" /> </xsl:attribute> <xsl:value-of select="@URL" /> </a> <br /> <xsl:value-of select="@description" /> <br /> </xsl:template> </xsl:stylesheet>
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements
xsl:sort, xsl:with-param
only for RuBoard |