Last active
August 17, 2020 05:20
-
-
Save hh2k/7a72a52ee4f9f3cb13b4d7171a8ab5db to your computer and use it in GitHub Desktop.
XSLT - split string and loop
This file contains hidden or 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: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