xsl-list
[Top] [All Lists]

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

2007-09-12 20:08:13
Alice,

When you define image_src variable, there is a context there (The context is not in graphic element aparently). If there is not an url attribute for current element, you will get empty when you say <xsl:value-of select="./@url"/>. So the result is 0.

If you change your program to:

<xsl:template match="graphic">
        <xsl:value-of select="string-length(@url)"/>
</xsl:template>

OR:

<xsl:template match="graphic">
        <xsl:variable name="image_src">
        <xsl:value-of select="./@url"/>
        </xsl:variable>
        <xsl:value-of select="string-length($image_src)"/>
</xsl:template>

It should work.

Hope this helps.

Jingjun


Alice Wei 写道:
Hi,
 I am trying to create different sets of output based on the length of the 
"string" of my variable. Below are the lines I used for calculation:

 <xsl:variable name="image_src">
        <xsl:value-of select="./@url"/>
    </xsl:variable>

 <xsl:template match="graphic">
        <xsl:value-of select="string-length($image_src)"/>
</xsl:template>


If I have XML like: <graphic url="0125"/>. the result is supposed to come out with 4. And, likewise, 
<graphic url="123456"/> should come out with 6. However, when I run the XSLT, it only gives me 
"0". Is there something I have done wrong?

Thanks to those who may help.

Alice





--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--