Skip to content

Instantly share code, notes, and snippets.

@hh2k
Last active August 17, 2020 05:20
Show Gist options
  • Select an option

  • Save hh2k/7a72a52ee4f9f3cb13b4d7171a8ab5db to your computer and use it in GitHub Desktop.

Select an option

Save hh2k/7a72a52ee4f9f3cb13b4d7171a8ab5db to your computer and use it in GitHub Desktop.
XSLT - split string and loop
<xsl:template name="tokenize">
<xsl:param name="text"/>
<xsl:param name="sep" select="','"/>
<xsl:choose>
<xsl:when test="contains($text, $sep)">
<p>
<xsl:value-of select="substring-before($text, $sep)"/>
</p>
<!-- recursive call -->
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="substring-after($text, $sep)" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:value-of select="$text"/>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Usage:
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="1,2,3,4,5"/>
</xsl:call-template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment