[xsl] Mutability of variables

Subject: [xsl] Mutability of variables
From: Meeraj Kunnumpurath <mkunnumpurath@xxxxxxxxxxxxxx>
Date: Wed, 22 Sep 2010 13:47:25 +0100

I realize XSLT variables are immutable. However, I have a requirement
to split a piece of text into multiple lines based on a pre-defined
length respecting word boundaries. This means if the last word on a
line doesn't fit into the current line, the whole word needs to be
moved into a new line. I am using XSLT 2.0 with Saxon 9.* HE.

My initial thinking was to do something like below, without using recursion

  <xsl:function name="gpg:split-name-1">
        <xsl:param name="line" />
        <xsl:for-each select="tokenize(normalize-space($line), ' ')">
            // Keep track of the current length and introduce a break
and reset the length when the length exceeds the max line length

However, since the variables are immutable, I am unable to keep track
of the current length. Is there a way to do this using standard XSLT
2.0 constructs and not using recursion?

Kind regards

Current Thread