RE: [xsl] String as Node

Subject: RE: [xsl] String as Node
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 19 May 2003 14:43:59 -0400
[ Karl J. Stubsjoen]

> If an attribute contains a string, and that string's value is a space
> delimited value of numbers and I want to loop (verbiage?) 
> through each of
> those numbers like it was a node list (verbiage?), how could 
> I do this?
> SO:
> <myxml>
>     <anyelement anyatt="1 2 3 4 5 6 7 8 9 10"/>
> </myxml>

You can either look up one of the tokenizer extensions, like the one
Dimitre has in his FXSL package - just look in the FAQs - or you can
write a simple recursive template yourself.  Here is an example.  You
will notice that there are a few tests for empty values of the
variables.  The test for $first is needed because substring-before will
return an empty string if there is no space in the string.  Of course
the tests can be arranged differently (you could use

The point is to split off the first item and do something with it, then
call the template again the the remaining fragment.

<xsl:stylesheet version="1.0"

<xsl:template match="/myxml">
	<xsl:call-template name='split'>
		<xsl:with-param name='data'

<xsl:template name='split'>
	<xsl:param name='data'/>
	<xsl:variable name='first' select='substring-before($data,"
	<xsl:variable name='rest' select='substring-after($data," ")'/>
	<xsl:if test='$first'><xsl:value-of
	<xsl:if test='$rest'>
		<xsl:call-template name='split'>
			<xsl:with-param name='data' select='$rest'/>
	<xsl:if test='not($rest)'><xsl:value-of



Tom P

 XSL-List info and archive:

Current Thread