gary A.K.A. G4
gary A.K.A. G4

Reputation: 1053

Using xsl:if to check the value of a node

I want to check if the node <Type> is either "Debit" or "Credit"

so that I can transform the information from just credit card information into Debit or Credit transactions.

any suggestion????

Upvotes: 0

Views: 517

Answers (2)

developer
developer

Reputation: 7400

I particularly like using xsl:choose in most situations. It provides the most flexibility. I also would use a variable outside the template for type.

Variable code (belongs outside templates):

<xsl:variable name="$type">
    <xsl:value-of select="//type" />
</xsl:variable>

xsl:choose code (belongs in a template):

<xsl:choose>
    <xsl:when test="$type='credit'">
        <xsl:text>Type is credit card</xsl:text>
    </xsl:when>
    <xsl:when text="$type='debit'">
        <xsl:text>Type is debit card</xsl:text>
    </xsl:when>
    <xsl:otherwise>
        <xsl:text>Type is neither debit or credit card</xsl:text>
    </xsl:otherwise>
</xsl:choose>

Hope this helped :)

Upvotes: 1

Kathy Van Stone
Kathy Van Stone

Reputation: 26281

The element xsl:if is for "if A do B else do nothing". Use xsl:choose (with xsl:when and xsl:otherwise) for "if A do B else do C". Otherwise we do need a more specific example of what you mean.

Upvotes: 2

Related Questions