assigning an elements content to variable and then testing

Discussion in 'XML' started by Ian Rutgers, Feb 2, 2005.

  1. Ian Rutgers

    Ian Rutgers Guest

    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

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Ian Rutgers, Feb 2, 2005
    #1
    1. Advertising

  2. Ian Rutgers

    Joris Gillis Guest

    Tempore 20:15:14, die Wednesday 02 February 2005 AD, hinc in foro {comp.text.xml} scripsit Ian Rutgers <>:

    > <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,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Vincit omnia simplicitas
    Keep it simple
     
    Joris Gillis, Feb 2, 2005
    #2
    1. Advertising

  3. Ian Rutgers

    Ian Rutgers Guest

    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!
     
    Ian Rutgers, Feb 2, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Morris
    Replies:
    3
    Views:
    905
    Roedy Green
    Feb 4, 2006
  2. Replies:
    0
    Views:
    328
  3. Andrew
    Replies:
    9
    Views:
    140
    Brian McCauley
    Jun 14, 2005
  4. Replies:
    4
    Views:
    554
    cwdjrxyz
    Jan 17, 2006
  5. weston
    Replies:
    1
    Views:
    274
    Richard Cornford
    Sep 22, 2006
Loading...

Share This Page