xsl-list
[Top] [All Lists]

[xsl] Constructing a sequence: numbers are added up repeatedly

2011-11-03 07:12:52
Hi,

Given
   <xsl:variable name="t1" select="'Mlmlmhmhmvmv'"/>
then
   <xsl:variable name="t4" select="for  $i in 1 to string-length($t1) return
      if (substring($t1, $i, 1)=('h', 'v')) then 0 else
      if (substring($t1, $i, 1)='z') then -1 else 1"/>
   <xsl:variable name="t5" select="for $i in 1 to string-length($t1)
      return $i + sum(subsequence($t4, 1, $i - 1))"/>
gives me what I want in $t5:
   1 3 5 7 9 11 12 14 15 17 18 20

While $t4 isn't very efficient, the construct in $t5 is simply unacceptable
for longer strings: the numbers are added up repeatedly instead of adding
only one number to the previous sum.

Any better solution would be appreciated, thanks!

Regards,
Manfred

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

<Prev in Thread] Current Thread [Next in Thread>