Jump to content

Use split semicolons within xslt


Johan1974

Recommended Posts

Hello is it possible to use xslt to go from Code:<XML> <TAG1>tag1value1;tag1value2</TAG1> <TAG2>tag2value1;tag2value2</TAG2> </XML>To thisCode:<XML> <LINE> <TAG1>tag1value1</TAG1> <TAG2>tag2value1</TAG2> </LINE> <LINE> <TAG1>tag1value2</TAG1> <TAG2>tag2value2</TAG2> </LINE></XML>Any help would be most appreciated.Johan

Link to comment
Share on other sites

  • 1 month later...

Try this one with 2.0:<?xml version="1.0" ?><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <XML> <xsl:apply-templates/> </XML></xsl:template> <xsl:template match="TAG1 | TAG2"> <LINE> <xsl:analyze-string select="text()" regex="([a-zA-Z0-9]+)(;)"> <xsl:matching-substring> <xsl:choose> <xsl:when test=".[position() = 1]"> <TAG1><xsl:value-of select="replace(.,';','')"/></TAG1> </xsl:when> <xsl:when test=".[position() = last()]"> <TAG2><xsl:value-of select="replace(.,';','')"/></TAG2> </xsl:when> <xsl:otherwise> <TAG1><xsl:value-of select="replace(.,';','')"/></TAG1> </xsl:otherwise> </xsl:choose> </xsl:matching-substring> <xsl:non-matching-substring> <TAG2><xsl:value-of select="replace(.,';','')"/></TAG2> </xsl:non-matching-substring> </xsl:analyze-string> </LINE> </xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...