Re: testing strings

Subject: Re: testing strings
From: Michel CASABIANCA <casa@xxxxxx>
Date: 17 Nov 1999 00:31:36 +0100
Bill Abbas <babbas@xxxxxxxxxx> writes:
> Pretty basic question about how to handle strings.  If I have an element in
> XML like so
> 
>          	<Whatever>
>                 <Choice>
>                     true
>                 </Choice>
> 	</Whatever>
>             
> And I want to output one of two values, depending on whether the Choice
> element is true or false.  
> 
> The following transform doesn't seem to do the trick.
> 
> 	<xsl:template match="Whatever">
> 	        <xsl:choose>
>             	    <xsl:when test="{Choice}='true')">
> 	                        Choice is true
>             	    </xsl:when>
> 	                <xsl:otherwise>
>             	            Choice is false
> 	                </xsl:otherwise>
> 	        </xsl:choose>
> 	</xsl:template>
> 
> What is the proper syntax for a test to compare strings?  Thanks.

I would rather do this way:

<Whatever>
   <true/>
</Whatever>

or

<Whatever>
</Whatever>

if not true.

Yu could perform the test this way:

<xsl:template match="Whatever">
   <xsl:choose>
      <xsl:when test="true">
         Choice is true
      </xsl:when>
      <xsl:otherwise>
         Choice is false
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

This is more readable and efficient in my opinion.

-- 
Michel CASABIANCA
mailto:casa@xxxxxx
http://www.sdv.fr/pages/casa


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread