if statement for multiple tables
Hi All,
I wanted to code in xsl, two tables based on the if condition something like below
if (cond=true)
create table 1
else
create table 2
endif
please someone help me in writing this code in xsl.
Thanks in advance.
[285 byte] By [
chiru123] at [2007-11-19 11:11:53]

# 1 Re: if statement for multiple tables
Here is an example of using <xsl:choose> to produce two different tables (not that different, one is pink, the other is blue) based on an attribute:
The data:
<persons>
<person gender="male">
<name>Petter</name>
</person>
<person gender="female">
<name>Kristine</name>
</person>
</persons>
The template:
<xsl:template match="/">
<xsl:for-each select="/persons/person">
<xsl:choose>
<!-- is it a male? -->
<xsl:when test="@gender='male'">
<table bgcolor="blue">
<tbody>
<tr>
<td><xsl:value-of select="."/></td>
</tr>
</tbody>
</table>
</xsl:when>
<!-- or is it not? -->
<xsl:otherwise >
<table bgcolor="pink">
<tbody>
<tr>
<td><xsl:value-of select="."/></td>
</tr>
</tbody>
</table>
</xsl:otherwise >
</xsl:choose>
</xsl:for-each>
</xsl:template>
and the reuslt:
<table bgcolor="blue">
<tbody>
<tr>
<td>Petter</td>
</tr>
</tbody>
</table>
<table bgcolor="pink">
<tbody>
<tr>
<td>Kristine</td>
</tr>
</tbody>
</table>
- petter