Important Notes
There are two key parts to XSLT processing:
- Selecting the nodes or elements to be processed (using a match pattern of XPath or XQuery) by defining a template
- Applying the processing to the selected nodes by using a templates
- Accessing the selected node values
Selecting Nodes
The basic XSLT element for selecting a node is :
<xsl:template match=pattern>
Actions to be taken or text to be written out
</xsl:templates>
When the XSLT processor matches a template's pattern, the node or node set becomes the context node / node set. You can also refer to the current node as '.'
By default a template only matches the the current element and attributes, rather than any children.
Applying Logic to Nodes
The basic construct for applying the logic is:
<xsl:apply-template>
The apply-templates construct only applies to nodes or child nodes, but not to attributes. This can addressed by using the select construct in the apply-templates construct.
To apply a specific template the full construct becomes:
<xsl:apply-template select="xpath expression">
You can also apply a names template by substituting the final select section with:
<xsl:call-template name="templatename"> </xsl:call-template>
and adding in:
<xsl:template name="templatename"> </xsl:template>
You can also specifiy prameters to pass to the called template by using the
<xsl:param>
and
<xsl:with-param>
inside the called template.
Accesing Node Values
In order to get the value of a node the construct is:
<xsl:value-of select="xpath expression">