xsl-list
[Top] [All Lists]

[xsl] split string to whole words based on length

2006-04-26 08:06:58
I'm sure there's a good xslt 2.0 way of doing this that doesn't
involve a recursive named template or function.  In fact I'm sure it's
come up a few times but I can't find it in the archives.

Given a string of comma delimeted words and a length, split the string
into substrings so that whole words are kept intact with proper use of
the delimiter, where no string exceeds the length.

So, given the following:

<xsl:variable name="str" select="'one,two,three,four,five'" as="xs:string"/>
<xsl:variable name="length" select="10" as="xs:integer"/>

Should be output as:

<words>one,two</words>
<words>three,four</words>
<words>five</words>

As I say, I'm sure there's a quality solution to this, rather than the
long winded recursive approach.

Any takers?

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