Jump to content

Use split semicolons within xslt

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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...