I would like to split an XML string with a delimiter(_) and would like to store each value in a variable using XSL. I am using xsl1.0
My xml file
<file>
<filename>ACT_0815_ERS_V7</filename>
</file>
and XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="filename/text()" name="tokenize">
<xsl:param name="text" select="."/>
<xsl:param name="separator" select="'_'"/>
<xsl:choose>
<xsl:when test="not(contains($text, $separator))">
<item>
<xsl:value-of select="normalize-space($text)"/>
</item>
</xsl:when>
<xsl:otherwise>
<aa><xsl:value-of select="normalize-space(substring-before($text[0], $separator))"/></aa>
<bb><xsl:value-of select="normalize-space(substring-before($text[1], $separator))"/></bb>
<cc><xsl:value-of select="normalize-space(substring-before($text[2], $separator))"/></cc>
<dd><xsl:value-of select="normalize-space(substring-before($text[3], $separator))"/></dd>
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="substring-after($text, $separator)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Bugged xml output for the above xsl
<?xml version="1.0" encoding="UTF-8"?>
<file>
<filename><aa/><bb>ACT</bb><cc/><dd/><aa/><bb>0815</bb><cc/><dd/><aa/><bb>ERS</bb><cc/><dd/><item>V7</item></filename>
</file>
Want to have the output as follows
<?xml version="1.0" encoding="UTF-8"?>
<file>
<aa>ACT</aa>
<bb>0815</bb>
<cc>ERS</cc>
<dd>V7</dd>
</file>