XSLT - Basic template elements

 

 

Use the XSLT elements below to define templates that specify how to process selected input elements.

xsl:template: Define a template
xsl:variable: Define a global or local variable

You can define a variable and set its value using the xsl:variable element. Once you have defined a variable, you can refer to it in any XPath expression by using a dollar sign ($) followed by the name of a variable.

There are two kinds of variables:

    A global variable's value is available everywhere in your stylesheet. To define a global variable, place the xsl:variable element as a child of the root stylesheet element.

    The value of a local variable is available only inside the element where it is declared.

There are two ways to specify the value of your variable. You can use an XPath expression in the select attribute and the variable will take on the value of that expression. You can, instead, place the value in the content of the xsl:variable element. For example, these two elements have the same effect:

    <xsl:variable name="child-page" select="'child.html'"/>
    <xsl:variable name="child-page">child.html</xsl:variable>

Note in the first example above that the value of the select attribute has two levels of quotes. This is necessary because in XPath names usually refer to child elements. If you want an attribute to have a string constant as its value, you must provide a second level of quotes inside the quotes that surround the attribute value.

Here are the attributes of the xsl:variable element:

select

    The value you are assigning to this variable.

xsl:variable: Define a global or local variable
 xsl:apply-templates: Process a node set with appropriate templates
 xsl:include: Insert another stylesheet
 xsl:param: Define an argument to be passed into a template
 xsl:with-param: Pass an argument to a template
 

source: http://infohost.nmt.edu/~shipman/doc/xslt/web/template-elts.html