Reputation: 3966
I have 2 condition to check true or false and take a certain action.
Here is my code.
<xsl:variable name="hac" select="Hac1"/>
<xsl:choose>
<xsl:when test="$hac= 'false'">
<p style="display:inline">Hac1: </p><input type="checkbox" disabled="disabled" >
</xsl:when>
<xsl:otherwise>
<p>HACCP: </p><input type="checkbox" disabled="disabled" checked="checked">
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="glo1" select="Gloves"/>
<xsl:choose>
<xsl:when test1="$glo1= 'false'">
<p style="display:inline">Gloves: </p><input type="checkbox" disabled="disabled" >
</xsl:when>
<xsl:otherwise>
<p>Gloves: </p><input type="checkbox" disabled="disabled" checked="checked">
</xsl:otherwise>
</xsl:choose>
This only displays my Hac1 and not my Gloves, and i don't know what seems to be the problem.
Upvotes: 2
Views: 3688
Reputation: 243469
The provided XSLT code has a number of obvious errors and any compliant XSLT processor (or even XML parser) should raise errors and not produce any output at all:
The <input>
elements aren't closed -- this males the whole stylesheet non-well-formed XML document.
The <xsl:when>
instruction cannot have an attribute named "test1"
-- only "test" attribute is allowed.
When I corrected these two errors, the transformation now is:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<xsl:variable name="hac" select="Hac1"/>
<xsl:choose>
<xsl:when test="$hac= 'false'">
<p style="display:inline">Hac1: </p><input type="checkbox" disabled="disabled" />
</xsl:when>
<xsl:otherwise>
<p>HACCP: </p><input type="checkbox" disabled="disabled" checked="checked"/>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="glo1" select="Gloves"/>
<xsl:choose>
<xsl:when test="$glo1= 'false'">
<p style="display:inline">Gloves: </p><input type="checkbox" disabled="disabled" />
</xsl:when>
<xsl:otherwise>
<p>Gloves: </p><input type="checkbox" disabled="disabled" checked="checked"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
and it produces normal-looking results.
When applied on this XML document (none was provided!):
<t>
<Hac1>true</Hac1>
<Floves>false</Floves>
</t>
the result is:
<p>HACCP: </p>
<input type="checkbox" disabled="disabled" checked="checked"/>
<p>Gloves: </p>
<input type="checkbox" disabled="disabled" checked="checked"/>
Upvotes: 1
Reputation: 19953
Assuming this is a direct copy/paste from your XSLT, you have several errors, so I'm amazed you actually get anything.
All four of the <input>
tags are missing their closure, so change the final part from >
to />
on each one... for example...
<input type="checkbox" disabled="disabled" />
Then you have <xsl:when test1=...
which is incorrect. It should be <xsl:when test=...
(note the lack of the 1
)...
<xsl:when test="$glo1= 'false'">
Upvotes: 1