assigning an elements content to variable and then testing

I

Ian Rutgers

In transforming the <towing> element (boolean) I want the xlst document
test the <towing> element for the "true" text and if found output
"available", otherwise output "not available". While the complete code
is on http://www.otima.ca/XML/auto2.xslt from auto.xml .. below is the
relevant snippet.

The code below always evaluates to "false" showing "not available" ...
what I am doing wrong?

<tr>
<td class="autoDescr">Towing</td>
<td><xsl:variable name="towingCapable" select=".//towing/text()"
/>
<xsl:choose>
<xsl:when test="$towingCapable=true">
<xsl:text>Available</xsl:text>
</xsl:when>
<xsl:eek:therwise> <xsl:text>Not Available</xsl:text>
</xsl:eek:therwise>
</xsl:choose></td>
</tr>

Thank you,

Ian
 
J

Joris Gillis

Tempore 20:15:14 said:
<tr>
<td class="autoDescr">Towing</td>
<td><xsl:variable name="towingCapable" select=".//towing/text()"
/>
<xsl:choose>
<xsl:when test="$towingCapable=true">
<xsl:text>Available</xsl:text>
</xsl:when>
<xsl:eek:therwise> <xsl:text>Not Available</xsl:text>
</xsl:eek:therwise>
</xsl:choose></td>
</tr>
Hi,

Try quoting the string value to which the variable must be tested.
<xsl:when test="$towingCapable='true'">.
otherwise, your checking if there exists a 'true' child element with a string value equal to the variable.

It could also be that whitespaces are spoiling the test. In that case, declae your variable thus:
<xsl:variable name="towingCapable" select="normalize-space(.//towing/text())"/>

regards,
 
I

Ian Rutgers

Hi Joris,

Your suggestion: Try quoting the string value to which the variable must
be tested.
<xsl:when test="$towingCapable='true'"> did the trick!


Thank you,

Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,838
Latest member
KandiceChi

Latest Threads

Top