xsl:template

only for RuBoard

xsl:template

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.

Attributes

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.

 

Example

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" graphics/ccc.gif description="Available books by New Riders" />       <link id="vbdna" URL="http://www.xmlandasp.net" name="Xmlandasp.net" graphics/ccc.gif description="Articles and samples available for VB, DNA, and .NET" />       <link id="gotdotnet" URL="http://www.gotdotnet.com" name="GotDotNet.com" graphics/ccc.gif description="Samples, walkthroughs, and more" />       <link id="msdn" URL="http://msdn.microsoft.com/library" name="MSDN Online Library" graphics/ccc.gif description="MSDN Online" />       <link id="devx" URL="http://www.devx.com" name="DevX.com" description="Fawcette graphics/ccc.gif 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">                       &#035;<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> 

Parent Elements

 xsl:stylesheet, xsl:transform 

Child Elements

 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


XML and ASP. NET
XML and ASP.NET
ISBN: B000H2MXOM
EAN: N/A
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net