XSL 1.0 Split function#

Been spending a little more time than I'd like with XSLT.  I recently needed a split function that would recursively create elements based on a delimited string.  Well, although XSLT 2.0 appears to have support for split, 1.0 does not.  So here goes for anyone who might need it.

<xsl:template match="some_delimited_string">
   <xsl:if test="normalize-space(.)">
      <xsl:call-template name="split">
         <xsl:with-param name="text" select="."/>
         <xsl:with-param name="element">YourElementName</xsl:with-param>
         <xsl:with-param name="delim">/</xsl:with-param>
      </xsl:call-template>
   </xsl:if>
</xsl:template>

<xsl:template name="split">
   <xsl:param name="text" select=""/>
   <xsl:param name="element" select=""/>
   <xsl:param name="delim" select=""/>
   <xsl:choose>
      <xsl:when test="contains($text, $delim)">
         <xsl:element name="{$element}">
            <xsl:value-of select="substring-before($text, $delim)"/>
         </xsl:element>
         <xsl:call-template name="split">
            <xsl:with-param name="text" select="substring-after($text, $delim)"/>
            <xsl:with-param name="element" select="$element"/>
            <xsl:with-param name="delim" select="$delim"/>
         </xsl:call-template>
      </xsl:when>
   <xsl:otherwise>
      <xsl:element name="{$element}">
         <xsl:value-of select="$text"/>
      </xsl:element>
   </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

All content © 2009, Vincent Tripodi
On this page
This site
Calendar
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Archives
Blogroll OPML
Disclaimer

All content on this blog has somehow touched the mind of a desperate individual looking for attention from anywhere he can get it.  Do not hold anyone responsible for what appears here except the author.  Sue me, not my employer.  I welcome the attention.

Send mail to the author(s) Vincent Tripodi