XSLT 1.0 : Iterate over characters in a string

Posted by subtenante on Stack Overflow See other posts from Stack Overflow or by subtenante
Published on 2010-05-06T14:36:07Z Indexed on 2010/05/06 14:38 UTC
Read the original article Hit count: 303

Filed under:
|

I need to iterate over the characters in a string to build an XML structure.

Currently, I am doing this :

<xsl:template name="verticalize">
    <xsl:param name="text">Some text</xsl:param>
    <xsl:for-each select="tokenize(replace(replace($text,'(.)','$1\\n'),'\\n$',''),'\\n')">
        <xsl:element name="para">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:for-each>
</xsl:template>

This produces something like :

<para>S</para>
<para>o</para>
<para>m</para>
<para>e</para>
<para> </para>
<para>t</para>
<para>e</para>
<para>x</para>
<para>t</para>

This works fine with Xpath 2.0. But I need to apply the same treatment in a XPath 1.0 environment, where the replace() method is not available.

Do you know a way to achieve this ?

© Stack Overflow or respective owner

Related posts about xslt-1.0

Related posts about xpath