-1

Hello I'm trying it again, becouse I can't find an answer to my question...

I have this XML input

<Name> Name1, Name2</Name>

And in XML output I need to get this

<NameOfFirstOne>Name1 </NameOfFirstOne>
 <NameOfSecondOne>Name2 </NameOfSecondOne>  

But if I do value of I always get both names, but I just need one. So what can I do with it?

1 Answers1

1

If you have XPath 3.1 (i.e. XSLT 2.0), then you can use the tokenize() function for splitting your string by a specified separator string:

<xsl:template match="Name">
    <xsl:variable name="names" select="tokenize(text(),', ')"/>
    <NameOfFirstOne>
        <xsl:value-of select="$names[1]"/>
    </NameOfFirstOne>
    <NameOfSecondOne>
        <xsl:value-of select="$names[2]"/>
    </NameOfSecondOne>
</xsl:template>
Kim Homann
  • 3,042
  • 1
  • 17
  • 20