user12504491
user12504491

Reputation:

Adding If else condition in xsl stylesheet?

I am using xslt1 This is chunk of my xsl stylesheet now I Want to add condtion in that if value of account status is closed then change background color to red else green ? How can we achieve that here

 <th>
        Account Status:-
    </th>
    <td>

        <xsl:value-of select="ACCOUNT-STATUS" />

    </td>

Upvotes: 0

Views: 91

Answers (2)

Martin Honnen
Martin Honnen

Reputation: 167581

In XSLT 1, you can use

<th>
  <xsl:attribute name="style">
     <xsl:text>background-color: </xsl:text>
     <xsl:choose>
        <xsl:when test="ACCOUNT-STATUS = 'closed'">red</xsl:when>
        <xsl:otherwise>green</xsl:otherwise>
     </xsl:choose>
   </xsl:attribute>
   <xsl:value-of select="ACCOUNT-STATUS" />
</th>

Upvotes: 0

Michael Kay
Michael Kay

Reputation: 163360

Another option is to do something like

<th class="account-status-{ACCOUNT-STATUS}">...</th>

And then set up CSS styles named account-status-open and account-status-closed.

Upvotes: 1

Related Questions