Firstly, you don't need to write this. It's been done before: see
http://www.exslt.org/str/functions/tokenize/str.tokenize.template.xsl
(use "view source" in your browser if nothing shows).
But the only thing wrong with your code, as far as I can see, is that
the variable $tlist is not a sequence of elements, but a document node
that is the owner of that sequence of elements.
Michael Kay
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Hayk, Matthias
Sent: 02 May 2003 10:01
To: 'XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: [xsl] Node-List in Variables
Hello,
i want to tokenize a string, delimited with a special
character, into its tokens and want this tokens to be a
result-tree which i can handle with an xsl:for-each.
myexample
the first xsl:variable call the template tokenizer which
creates the t1-elements recursivly for all string elements
(a, b and c). i would expect that the variable tlist contains
<t1>a</t1><t1>b</t1><t1>c</t1> which i then want to work on
with the xsl:for-each, but the xslt-processor gives the error
that the expression in xsl:for-each must evaluate to a
node-set. if i use the ms-xslt-nodeset function i get only
one node which contains the textvalues of the elements ( in
my example it containt abc). so it seems, that tlist only
contains a string.
any idea what is wrong and how i can achieve my goal?
regards
matthias
<xsl:variable name="tlist">
<xsl:call-template name="tokenizer">
<xsl:with-param name="tokenstr" select="a|b|c|"/>
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="$tlist">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:template name="tokenizer">
<xsl:param name="tokenstr"/>
<xsl:variable name="akttoken"
select="normalize-space(substring-before($tokenstr,'|'))"/>
<xsl:if test="string-length($akttoken) > 0">
<!-- Ist noch nen Token da -->
<xsl:element name="t1">
<xsl:value-of select="$akttoken"/>
</xsl:element>
<xsl:call-template name="tokenizer">
<xsl:with-param name="tokenstr"
select="substring-after($tokenstr,'|')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list