Created
May 10, 2011 11:38
-
-
Save emiliano-poggi/964314 to your computer and use it in GitHub Desktop.
XSLT: Split list in tokens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<root> | |
<varlist>a.a.a b.b.b c.c.c</varlist> | |
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nodelist> | |
<id>a.a.a</id> | |
<id>b.b.b</id> | |
<id>c.c.c</id> | |
</nodelist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output omit-xml-declaration="yes" indent="yes"/> | |
<xsl:template match="/root"> | |
<xsl:variable name="varList" select="varlist" /> | |
<xsl:variable name="nodelist"> | |
<xsl:call-template name="output-tokens"> | |
<xsl:with-param name="list"><xsl:value-of select="$varList"/></xsl:with-param> | |
</xsl:call-template> | |
</xsl:variable> | |
<nodelist> | |
<xsl:copy-of select="$nodelist"/> | |
</nodelist> | |
</xsl:template> | |
<xsl:template name="output-tokens"> | |
<xsl:param name="list" /> | |
<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" /> | |
<xsl:variable name="first" select="substring-before($newlist, ' ')" /> | |
<xsl:variable name="remaining" select="substring-after($newlist, ' ')" /> | |
<id> | |
<xsl:value-of select="$first" /> | |
</id> | |
<xsl:if test="$remaining"> | |
<xsl:call-template name="output-tokens"> | |
<xsl:with-param name="list" select="$remaining" /> | |
</xsl:call-template> | |
</xsl:if> | |
</xsl:template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/5947183/how-to-handle-sequence-or-array-of-strings-in-xsl-file/5948685#5948685