Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

replace char using XSLT

$
0
0

Hi All,

 

Iam trying to modify the json string as shown below

{"mbs":{"msg":{"i":"6796","c":"0","st":"031116180300","et":"031216180100","th":"brown","d":[{"data":"Welcome to Abraham's Party"}],"t":[{"data":"happy"}]}}}

and my task is to replace the single notation which exists only in the d attribute with & char and the final output should be s shown below

{"mbs":{"msg":{"i":"6796","c":"0","st":"031116180300","et":"031216180100","th":"brown","d":[{"data":"Welcome to Abraham&s Party"}],"t":[{"data":"happy"}]}}}
please find the XSLT that iam using currently

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
      <xsl:output method = "text" />
      <xsl:template match="/">
            <xsl:apply-templates select="mbs"/>
      </xsl:template>
      <xsl:template match="mbs">
            <xsl:text>{"mbs":{</xsl:text>
            <xsl:text>"msg":{</xsl:text>
            <xsl:for-each select="msg">
                  <xsl:text>"i":"</xsl:text><xsl:value-of select="@mid" /><xsl:text>",</xsl:text>
                  <xsl:text>"c":"</xsl:text><xsl:value-of select="@mr" /><xsl:text>",</xsl:text>
                  <xsl:text>"st":"</xsl:text><xsl:value-of select="@st" /><xsl:text>",</xsl:text>
                  <xsl:text>"et":"</xsl:text><xsl:value-of select="@et" /><xsl:text>",</xsl:text>
                  <xsl:text>"th":"</xsl:text><xsl:value-of select="@stt" /><xsl:text>"</xsl:text>
                  <xsl:text>,"d":[</xsl:text>
                  <xsl:for-each select="d">
                        <xsl:if test="position()=1">
                  <xsl:text>{"data":"</xsl:text><xsl:value-of select="."/><xsl:text>"}</xsl:text>
                        </xsl:if>
                  </xsl:for-each>
                  <xsl:text>]</xsl:text>
                  <xsl:text>,"t":[</xsl:text>
                  <xsl:for-each select="t">
                        <xsl:if test="position()=1">
                        <xsl:text>{"data":"</xsl:text><xsl:value-of select="."/><xsl:text>"}</xsl:text>
                        </xsl:if>
                  </xsl:for-each>
                  <xsl:text>]}</xsl:text>
            </xsl:for-each>
            <xsl:text>}}</xsl:text>
      </xsl:template>
</xsl:stylesheet>

Kindly help me on the same.

Thanks,

Ram



Viewing all articles
Browse latest Browse all 935

Trending Articles



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