[SOLVED] XSLT: Template to split strings based on a delimiter


I have been trying to come up with a template on transforming this:

<text>Smith, John / Smith, Dina / Smith, Susan</text>


    <name>Smith, John</name>
    <name>Smith, Dina</name>
    <name>Smith, Susan</name>

I am new to XSLT and I have been struggling to come up with a template to achieve the needed result. I have tried modifying the template here How to split strings, but I can’t achieve what I needed. Thanks in advance for the help.


Use this template:

<xsl:stylesheet version="1.0"
  <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="text()" name="split">
    <xsl:param name="pText" select="."/>
    <xsl:param name="index" select="1"/>
    <xsl:if test="string-length($pText)">
          <xsl:value-of select="$index"/>
          <xsl:value-of select="substring-before(concat($pText,'/'),'/')"/>
      <xsl:call-template name="split">
        <xsl:with-param name="pText" select="substring-after($pText, '/')"/>
        <xsl:with-param name="index" select="$index + 1"/>

Answered By – Kirill Polishchuk

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.