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>
Remember Me
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.
Vincent Tripodi