An XSLT Stylesheet
Let's start by looking at a simple XML document and an XSLT stylesheet which is used to transform the XML to HTML.
xsl:template tag is used to tell the XSLT processor what to do when it comes across a matching node. Matches are determined by the XPath expression in the
match attribute of the
Let's see what happens if we transform an XML document with multiple
FirstName elements against this same XSLT. Take, for example, the XML document below.
xsl:value-of element is used to output the text value of a node. To illustrate, let's look at the following example.
To illustrate this, let's look at another example.
Whitespace in an XSLT template is output literally. If you're not careful, this can lead to undesirable results. To illustrate, let's look at the following XML and XSLT documents.
When XsltBasics/Demos/WhiteSpace1.xml is transformed against XsltBasics/Demos/WhiteSpace1.xsl, the output looks like this:
There is an empty line before and after the text. There are also two tabs preceding the text. This is because the whitespace between
<xsl:template match="blurb"> and
Literal Text and the whitespace between
Literal Text and
</xsl:template> is output literally.
If you did not want that extra whitespace to show up in the output, you could use the following XSLT instead.
The examples above illustrate how
xsl:text can be used to remove whitespace. It can also be used to add whitespace where there otherwise wouldn't be any. Let's take a look at another example.