Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > assigning an elements content to variable and then testing

Reply
Thread Tools

assigning an elements content to variable and then testing

 
 
Ian Rutgers
Guest
Posts: n/a
 
      02-02-2005
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>
<xsltherwise> <xsl:text>Not Available</xsl:text>
</xsltherwise>
</xsl:choose></td>
</tr>

Thank you,

Ian

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      02-02-2005
Tempore 20:15:14, die Wednesday 02 February 2005 AD, hinc in foro {comp.text.xml} scripsit Ian Rutgers <(E-Mail Removed)>:

> <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>
> <xsltherwise> <xsl:text>Not Available</xsl:text>
> </xsltherwise>
> </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,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple
 
Reply With Quote
 
 
 
 
Ian Rutgers
Guest
Posts: n/a
 
      02-02-2005
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM
Slice returned hash or access to its elements without assigning to a variable Andrew Perl Misc 9 06-14-2005 05:09 PM



Advertisments