Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3316

Re: Need Help on XSLT Code

$
0
0

Hi Maheswarareddy Konda!

 

You can try something like this:

 

<?xml version='1.0'?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 

 

<xsl:template match="/">

 

  <Root>

  <xsl:apply-templates select="//String"/>

  </Root>

 

 

</xsl:template>

 

 

<xsl:template match="String">

 

 

  <xsl:call-template name="Split">

  <xsl:with-param name="srcStr" select="''"/>

  <xsl:with-param name="sep" select="''"/>

  <xsl:with-param name="restStr" select="text()"/>

  </xsl:call-template>

 

 

</xsl:template>

 

 

<xsl:template name="Split">

  <xsl:param name="srcStr"/>

  <xsl:param name="sep"/>

  <xsl:param name="restStr"/>

 

  <xsl:if test="string-length($restStr)">

 

 

  <xsl:variable name="token">

  <xsl:choose>

  <xsl:when test="contains($restStr, '.')">

  <xsl:value-of select="substring-before($restStr, '.')" />

  </xsl:when>

  <xsl:otherwise>

  <xsl:value-of select="$restStr" />

  </xsl:otherwise>

  </xsl:choose>

  </xsl:variable>

 

  <xsl:variable name="currText" select="concat($srcStr, concat($sep, $token))" />

 

  <item>

  <text> <xsl:value-of select="$currText"/> </text>

  </item>

 

  <xsl:call-template name="Split">

  <xsl:with-param name="srcStr" select="$currText" />

  <xsl:with-param name="sep" select="'.'" />

  <xsl:with-param name="restStr" select="substring-after($restStr, '.')" />

  </xsl:call-template>

 

 

  </xsl:if>

 

 

</xsl:template>

 

 

</xsl:stylesheet>

 

For source XML:

 

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MyMessage xmlns:ns0="urn://test">

<String>111.222.333.444.555</String>

</ns0:MyMessage>

 

Result is:

 

<?xml version='1.0' ?>

<Root>

<item><text>111</text></item>

<item><text>111.222</text></item>

<item><text>111.222.333</text></item>

<item><text>111.222.333.444</text></item>

<item><text>111.222.333.444.555</text></item>

</Root>

 

Probably It's not optimized as I wrote this transformation very quickly. You can modify it accordingly. The main idea is to use recursive template call.

 

Regards.


Viewing all articles
Browse latest Browse all 3316

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>