xsl:variable

only for RuBoard

xsl:variable

xsl:variable specifies a variable bound in an expression. A variable has scope, which means that a variable is only visible as a child of the parent element in which it was declared.

A variable's contents can be specified through either the select attribute or as a child element. For example, consider the declaration:

 <xsl:variable name="foo">  <xsl:value-of select="bar"/>  </xsl:variable> 

This declaration is equivalent to the following:

 <xsl:variable name="foo" select="bar"/> 

The difference is that the first method always binds the variable to a result-tree fragment, whereas the second method can bind the variable to a string or number.

Attributes

Attribute Name

Enforced

Description

Values

name

Required

The name of the variable.

QName

select

Optional

The value of the variable. If specified, the content of the xsl:variable element must be empty.

Expression

Example

Given the XML instance document, links.xml :

 <?xml version="1.0" encoding="utf-8" ?>  <links>       <link name="NewRiders.com" lastevaluated="2001-09-08T19:01:55"/>  </links> 

The following stylesheet would parse the last evaluated attribute to display the month number:

 <?xml version="1.0" encoding="UTF-8" ?>  <xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">       <xsl:template name="showmonth">            <xsl:param name="date" />            <xsl:text>Month:</xsl:text><xsl:value-of select="substring ($date, 6, 2)" />            </xsl:template>       <xsl:template match="/">            <xsl:apply-templates select="links/link" />       </xsl:template>       <xsl:template match="link">           <tr>                 <td>                     <xsl:call-template name="showmonth">                       <xsl:with-param name="date">                         <xsl:value-of select="@lastevaluated" />                        </xsl:with-param>                      </xsl:call-template>                 </td>            </tr>       </xsl:template>  </xsl:stylesheet> 

This results in the following output:

 <?xml version="1.0" encoding="UTF-16"?><tr><td>Month:09</td></tr> 

Parent Elements

 xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if,  xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:stylesheet  xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements 

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