[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: [XSL] Calculating Length of String Variables

Subject: Re: [XSL] Calculating Length of String Variables
From: jingjun long <longjingjun@xxxxxxxxx>
Date: Thu, 13 Sep 2007 11:07:30 +0800
Re:  [XSL] Calculating Length of String Variables
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 ei:
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.