xsl-list
[Top] [All Lists]

Re: [xsl] [XSL] Calculating Length of String Variables

2007-09-13 05:43:28
<

xsl:when test="string-length($image_src) = '4' or '5'">


that is a boolean or operator, which is true if either operand is
true. The first operand is true if 
string-length($image_src) = '4'
which is true if the string length of image source when converted to a
string is '4'. You meant
string-length($image_src) = 4
which would just test if teh length is 4 (which is the same thing, but
quicker)

the second operand to or is

'5'

a string, if used in a boolean context counts as true if it is non
empty, which is always teh case, so this is always true, so teh or
expression is always true.
you meant
string-length($image_src) = 5

so the whole thing can be wriiten as


<xsl:variabel name="l" select="string-length(@url"/>
<xsl:choose>
<xsl:when test="$l=4 or $l=4"><!- or in xpath 2 $l=(4,5) -->
<img src="images/{(_at_)url}"/>
</xsl:when>
<xsl:when test="$l=6">
<img src="images/{substring(@url,1,4)}.gif alt="Picture
No. {substring(@url,1,4)}"/>
</xsl:when>

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--