XSL Cheatsheet

The XSL Tags

xsl:template
A template
match
The tag this template processes.
mode
An additional identifier for this template
name
The name of the template. This is another way to identify this template to be processed. See xsl:call-template.
priority
A number indicating whether this matches better than another tag would.
xsl:apply-imports
Apply a template that has been imported at a lesser priority. In Saxon, you can use xsl:param with this. With the Microsoft DOM, doing that is an error.
xsl:apply-templates
Call the appropriate template for all tags. Will change the current node for purposes of matching.
select
The tags that should be processed.
mode
An additional identifier to the appropriate template.
xsl:attribute
Creates attributes in the element in which it is enclosed.
name
The name of the attribute.
xsl:attribute-set
A named group of “xsl:attribute” elements.
name
The name of this attribute-set.
xsl:call-template
Process the current tag with the specified template. This does not change the current node for purposes of matching. Only “xsl:apply-template” and “xsl:for-each” can do that.
name
The template to process.
xsl:choose
Somewhat complicated.
xsl:copy
Output the current node without children and attributes, unless specified with the appropriate parameter.
use-attribute-sets
The name of the attribute-set to output.
xsl:copy-of
Output everything within the selected node.
select
The node to output everything
xsl:element
Output an XML tag.
name
The name of the element. I believe that anything within curly brackets is evaluated.
xsl:for-each
Contains a template that is applied to each node selected. Will change the current node for purposes of matching.
select
The XPath of nodes to process.
xsl:if
A Boolean test to see if the contents should be used.
test
The Boolean test.
xsl:import
Subfiles can’t see items imported by the parents.
xsl:number
Output a number. The default is the index of the element within its parent.
level
If “multiple” then output a dotted number that also includes the ancestors’ position.
format
A text string describing how the number should be formatted.
value
Instead of the index, output this number.
xsl:output
Specify the format of the output.
xsl:param
Sets a name to a value. The value can be set through a “select” parameter, or through the output of its contents. Paths will not be evaluated for their results within the contents, but will within the select. This is similar to the “xsl:variable” tag, except this value is just a default and can be changed.
name
The name of the parameter.
select
The value of the parameter. If this is a path, it will be evaluated.
xsl:sort
If within an “xsl:apply-templates” or “xsl:for-each” will specify the order that the processing should be done.
case-order
“upper-first” or “lower-first”
data-type
“text” or “number”
order
“ascending” or “descending”
select
The key to sort on.
xsl:text
Output the enclosed text.
xsl:value-of
Output the evaluated text. If just a tagname, it won’t show child tags, but will show their content.
select
A function. Can be a tagname or an attribute. Or even “.”.
xsl:variable
Sets a name to a value. The value can be set through a “select” parameter, or through the output of its contents. Paths will not be evaluated for their results within the contents, but will within the select.
name
The name of the variable.
select
The value of the variable. If this is a path, it will be evaluated.
xsl:with-param
When this tag appears within an “xsl:apply-templates” any parameters within that template with the same name are replaced with the value specified here. This is identical to an xsl:param concerning attributes.

Functions

tagName
The text content of the tag. It won’t show child tags, but will show their contents.
@attribute
The text of an attribute
name()
The name of the current tag.

XPath Stuff

When using a predicate ([]), remember the index starts with 1 in XPath.

child::
The immediate child. The default axis.
descendant::
The recursive children
parent::
The immediate parent. Can be abbreviated to “..”.
ancestor::
The recursive parents
following-sibling::
preceding-sibling::
following::
preceding::
See Apply-templates in XSL book for good example.
attribute::
Can be abbreviated to “@”.
namespace::
self::
Can be abbreviated to “.”.
descendant-or-self::
Can be abbreviated to “//”.
ancestor-or-self::