I try this, I modified the "Dimitre Novatchev" code, and works for me: (please excuse me for my English)
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<xsl:template match="/*">
<xsl:variable name="_keywords">
<xsl:call-template name="split-to-values">
<xsl:with-param name="_text" select="Keywords-comma-separated"/>
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($_keywords)/value">
<xsl:variable name="_keyword" select="."/>
<!-- ANY CODE -->
</xsl:for-each>
</xsl:template>
<xsl:template match="text()" name="split-to-values">
<xsl:param name="_text"/>
<xsl:if test="string-length($_text)">
<xsl:variable name="_value" select="substring-before($_text, ',')"/>
<xsl:variable name="_next" select="substring-after($_text, ',')"/>
<value>
<xsl:value-of select="$_value"/>
</value>
<xsl:call-template name="split-to-values">
<xsl:with-param name="_text" select="$_next"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
I hope it helps you
@Bugude ask
I have a string in which data is separated by a delimiter like "|" and
is present in a variable. I would like to create an array in the XSL
by dividing the above string based on the delimiter and would like to
access the same in the in a for loop
Then the string may be: "alfa,beta,gama,delta"
The delimiter is presented in a variable:
<xsl:variable name="_delimiter">,</xsl:variable>
I modified the template as:
<xsl:template match="text()" name="split-to-values">
<xsl:param name="_text"/>
<xsl:param name="_delimiter"/>
<xsl:if test="string-length($_text)">
<xsl:variable name="_value" select="substring-before($_text, $_delimiter)"/>
<xsl:variable name="_next" select="substring-after($_text, $_delimiter)"/>
<value>
<xsl:value-of select="$_value"/>
</value>
<xsl:call-template name="split-to-values">
<xsl:with-param name="_text" select="$_next"/>
<xsl:with-param name="_delimiter" select="$_delimiter"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
And we can access to the nodes as similar an array with a for
<xsl:template match="/*">
<!-- _keyword as set a node -->
<xsl:variable name="_keywords">
<xsl:call-template name="split-to-values">
<xsl:with-param name="_text" select="'alfa,beta,gama,delta'"/>
<xsl:with-param name="_delimiter" select="$_delimiter"/>
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($_keywords)/value">
<xsl:variable name="_keyword" select="."/>
<!-- ANY CODE -->
<xsl:value-of select="$_keyword"/>
</xsl:for-each>
</xsl:template>
tokenize()extension function returns a node set or a result tree fragment (which can be turned into a node set using another extension function,node-set()). This node set can be accessed by index as you specified, because the elements representing tokens map one-to-one to children of a parent node, in order.