string - Does xslt have split() function? -


how split string based on separator?

given string topic1,topic2,topic3, want split string based on , generate:

topic1 topic2 topic3 

in xslt 1.0 have built recursive template. stylesheet:

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:template match="@*|node()">         <xsl:copy>             <xsl:apply-templates select="@*|node()"/>         </xsl:copy>     </xsl:template>     <xsl:template match="text/text()" name="tokenize">         <xsl:param name="text" select="."/>         <xsl:param name="separator" select="','"/>         <xsl:choose>             <xsl:when test="not(contains($text, $separator))">                 <item>                     <xsl:value-of select="normalize-space($text)"/>                 </item>             </xsl:when>             <xsl:otherwise>                 <item>                     <xsl:value-of select="normalize-space(substring-before($text, $separator))"/>                 </item>                 <xsl:call-template name="tokenize">                     <xsl:with-param name="text" select="substring-after($text, $separator)"/>                 </xsl:call-template>             </xsl:otherwise>         </xsl:choose>     </xsl:template> </xsl:stylesheet> 

input:

<root> <text>item1, item2, item3</text> </root> 

output:

<root>     <text>         <item>item1</item>         <item>item2</item>         <item>item3</item>     </text> </root> 

in xslt 2.0 have tokenize() core function. so, stylesheet:

<xsl:stylesheet version="2.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:template match="@*|node()">         <xsl:copy>             <xsl:apply-templates select="@*|node()"/>         </xsl:copy>     </xsl:template>     <xsl:template match="text/text()" name="tokenize">         <xsl:param name="separator" select="','"/>         <xsl:for-each select="tokenize(.,$separator)">                 <item>                     <xsl:value-of select="normalize-space(.)"/>                 </item>         </xsl:for-each>     </xsl:template> </xsl:stylesheet> 

result:

<root>     <text>         <item>item1</item>         <item>item2</item>         <item>item3</item>     </text> </root> 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -