We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 46,308 times

Contents

Related Categories

Extensible Markup Language (XML) Tutorial - XSL Transformations

gez

XSL Transformations

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>

I'm available for contract work. Please visit Juicify for details.

Comments

  • Excellent!

    Posted by Jet Blazer on 19 Jan 2006

    Beutiful article. Takes a user from a beginner level to an intermediate level very nicely. Certainly a treat for beginers and an expert alike.

  • Test

    Posted by prathiba on 04 Apr 2004

    Good article for starters