This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: string-length
- To: <xsl-list at mulberrytech dot com>
- Subject: RE: string-length
- From: "Ben Sorek" <bsorek at surfnotes dot com>
- Date: Sun, 2 Apr 2000 14:55:36 +0200
- Reply-To: xsl-list at mulberrytech dot com
Sorry for asking this question:
but where would I put this template name="add-data". I cannot put it in a
vriable tag, that won't work. If i place it outside, how does it "know" what
DATA is?
Ben
-----Original Message-----
From: owner-xsl-list@mulberrytech.com
[mailto:owner-xsl-list@mulberrytech.com]On Behalf Of Steve Tinney
Sent: Sunday, April 02, 2000 5:41 PM
To: xsl-list@mulberrytech.com
Subject: Re: string-length
> I want to select all nodes (in order) as long as the additive
> string length is less then 915
> <CATEGORY>
> <DATA>
> ....
> </DATA>
> <DATA>
> ....
> </DATA>
Use recursion, and pass the length of cumulative length of your string
as a parameter. Wrap the whole thing inside a variable.
<xsl:variable name="str">
<xsl:call-template name="add-data"/>
</xsl:variable>
<xsl:template name="add-data">
<xsl:param name="strlen" select="0"/>
<xsl:param name="index" select="1"/>
<xsl:if test="strlen < 915">
<xsl:value-of select="DATA[$index]"/>
</xsl:if>
<xsl:if test="$index <= count(DATA)">
<xsl:call-template name="add-data">
<xsl:with-param name="strlen"
select="$strlen+string-length(DATA[$index])"/>
<xsl:with-param name="index"
select="$index+1"/>
</xsl:call-template>
<xsl:if>
</xsl:template>
(Untested, and probably not exactly what you want when, e.g., the first
DATA node has more than 915 characters, but you get the idea)
Steve
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list