Basic Transformations
The value-of keyword is used to match a pattern and generates an element in the result tree containing the matched text.
<xsl:value-of select="/collection/cd/band" />
Element attributes are accessed using @. The following example matches the attribute year of the title element.
<xsl:value-of select="/collection/cd/title/@year" />
Selection
The if keyword is used for decision making. Conditions are placed in square brackets. The following example tests the paid attribute. If the paid attribute has a value of yes, then Fully Paid Member is displayed.
<xsl:if test=".[membership/@paid='yes']">Fully Paid Member</xsl:if>
Multiple conditions are performed using the choose keyword.
<xsl:choose>
<xsl:when test=".[membership/@paid='yes']">Fully
Paid Member</xsl:when>
<xsl:when test=".[membership/@paid='no']">Unpaid Member</xsl:when>
<xsl:otherwise>Unknown Payment Status</xsl:otherwise>
</xsl:choose>
Iteration
Iteration is achieved using the for-each keyword. The following example iterates through each cd in the collection and displays the band.
<xsl:for-each select="/collection/cd">
<xsl:value-of select="band" />
< /xsl:for-each>m
With iteration, the sort keyword may be used to sort elements selected by the select attribute. The following example displays the bands in ascending order.
<xsl:for-each select="/collection/cd">
<xsl:sort select="band" order="ascending" />
<xsl:value-of select="band" />
</xsl:for-each>
Comments