XML Glossary - 4 XSL

value-of to when

XSL:VALUE-OF.

<xsl:value-of select="pattern" />

Possibly the single most used element in XSLT. Value-of extracts the data from the XML structure. It can handle element contents and attributes. No processing is done - valid contents are output unchanged. Use @ to access attributes of elements, use . (period/full stop) to access the contents of the element itself. Refer to a child element directly (the element must be nested within the element that matched the template itself).

<xsl:value-of select="./@FILEBASE"/>.
<xsl:value-of select="."/>
<xsl:value-of select="HEADING" />

XSL:TEMPLATE. The second most used XSL element, possibly. Each XSL stylesheet needs at least one template match - the default match - match="/". This template should contain all the static code (<html> etc) that doesn't change between pages. Further templates then match specific elements - one by one. Templates don't have to include xsl:value-of instructions, empty XML elements can be matched with a template to insert code unchanged, e.g. in the example XML form the PASSWORD element inserts the same password input control into all XML files that contain the empty <PASSWORD /> element.

<xsl:template match="pattern">
</xsl:template>

XSL:TEXT. Insert text directly without relying on XML content.

<xsl:text>Insert text directly</xsl:text>

XSL:WHEN. Use alongside XSL:CHOOSE.

<xsl:template match="CODEHELP/NAVIGATE[@WWW]">
<xsl:choose>
<xsl:when test=".[first-of-type()]">
First Link:
</xsl:when>
<xsl:otherwise>
Subsequent Links:
<!-- all treated precisely the same way -->
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates />
</xsl:template>


This is part of www.codehelp.co.uk Copyright © 1998-2004 Neil Williams
See the file about.html for copying conditions.