This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
adding string-length values
- To: xsl-list at mulberrytech dot com
- Subject: adding string-length values
- From: Zeljko Rajic <Zeljko dot Rajic at brokat dot com>
- Date: Mon, 20 Nov 2000 19:13:04 +0100
- Organization: Brokat AG
- Reply-To: xsl-list at mulberrytech dot com
Hi out there,
I'm currently trying to develop a stylesheet which does some special
transformation depending on the length of single elements and the accumulated
legth of all (prior) elements. The source XML documents looks something like
this:
<?xml version="1.0" encoding="UTF-8"?>
<Article>
<Title>This is the title</Title>
<Para>This is the first paragraph.</Para>
<Para>This is the second paragraph.</Para>
<Para>And this is the last parahraph.</Para>
</Article>
In my stylesheet I'd like to do something like this:
<xsl:variable name="mycounter" select="0"/>
<xsl:for-each select="//Para">
<xsl:variable name="mycounter" select="$mycounter + string-length(.)"/>
<p>Number Chars: <xsl:value-of select="$mycounter"/></p>
</xsl:for-each>
Unfortunately this does not result in what I want to do. XSL does not allow to
change the value of 'mycounter' thus giving me the length of each <Para>
element:
Number Chars: 28
Number Chars: 29
Number Chars: 31
instead of the accumulated length of all <Para> elements:
Number Chars: 28
Number Chars: 57
Number Chars: 89
I guess the solution for the problem is quite easy, but at the moment I do not
see how I could achieve the wanted result. So I hope that somebody can give me a
hint how to add up the length of certain elements (here: <Para>) !
Many thanks for any help in advance!
- Zeljko
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list