only for RuBoard |
xsl:template defines a template rule that can generate result output. Template rules can be thought of several different ways. They can be thought of as functions with parameters (pull model programming). They can also be thought of as events, where a message is tested against all event declarations for an applicable event prototype (push model programming). They generally define a rule that is tested against a node.
Attribute Name | Enforced | Description | Values |
---|---|---|---|
name | Optional | Defines a named template that can be called as a function using the xsl:call- template element. | QName |
match | Optional | Identifies the source node or nodes to which the rule applies. | Pattern |
priority | Optional | Specifies the priority for the template rule, to be used for conflict resolution. If two templates with matching criteria are in the same scope, the priority attribute can determine which rule applies. | Number QName |
mode | Optional | Allows a template to be processed multiple times, each time producing a different result. |
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="vbdna" 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:
<?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:stylesheet, xsl:transform
xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:param, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements
only for RuBoard |