Working with Both xsl:if and xsl:choose in XSLT - Nesting xsl:choose within another
(Page 5 of 6 )
Up until now, we have seen several types of combinations using "xsl:if" and "xsl:choose." Now, we shall embed "xsl:choose" within another "xsl:choose."
In this case, I simply want to work with the same business need given in the previous section. The entire modified XSLT code for the same business need is as follows:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="1">
<xsl:apply-templates select="SQLData/Rows" />
</table>
</xsl:template>
<xsl:template match="SQLData/Rows">
<tr>
<td>
<xsl:value-of select="Empno"/>
</td>
<td>
<xsl:value-of select="Ename"/>
</td>
<xsl:apply-templates select="Sal" />
<td>
<xsl:value-of select="Deptno"/>
</td>
</tr>
</xsl:template>
<xsl:template match="Sal">
<xsl:choose>
<xsl:when test="text() > '2500' and text() < '4000'">
<xsl:choose>
<xsl:when test="./following::Deptno[1]/text() != '10'">
<td style="color: red">
<xsl:value-of select="."/>
</td>
</xsl:when>
<xsl:otherwise>
<td>
NA
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:value-of select="."/>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
You would receive the same output as discussed in previous section.
Next: Other scenarios >>
More ASP.NET Articles
More By Jagadish Chaterjee