Jesuraja
Jesuraja

Reputation: 3844

Condition based variable in XSLT

I am new to XSLT. Acutally I want to assign value to a variable color based on condition

<xsl:for-each select="report/task">
    <xsl:variable name="color" select="@status"/>
    ...
</xsl:for-each>

I want to assign different colors (red, yellow, green) based on status (Pending, Progress, Completed).

Upvotes: 0

Views: 104

Answers (1)

Jesuraja
Jesuraja

Reputation: 3844

I have found the solution:

<xsl:for-each select="report/task">
    <xsl:variable name="color">
        <xsl:choose>
            <xsl:when test="@status = 'Pending'">red</xsl:when>
            <xsl:when test="@status = 'Progress'">yellow</xsl:when>
            <xsl:when test="@status = 'Completed'">green</xsl:when>
            <xsl:otherwise>white</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
</xsl:for-each>

It is working...

Upvotes: 2

Related Questions