XML : XML to JSON with namespaces

I am trying to convert XML with XML namespace to JSON data using XSLT as shown below:

XML :

  <notification      xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf">      <event-time>2013-12-21T00:01:00Z</event-time>      <event xmlns="http://example.com/event/1.0">      <event-class>fault</event-class>      <reporting-entity>      <card>Ethernet0</card>      </reporting-entity>      <severity>major</severity>      </event>   </notification>    JSON Conversion:    {  "ietf-restconf:notification": {  "event-time": "2013-12-21T00:01:00Z",  "example-mod:event": {  "event-class": "fault",  "reporting-entity": { "card": "Ethernet0" },  "severity": "major"  }    

Using the below xslt :

  <?xml version="1.0"?>  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  <xsl:output method="text"/>    <xsl:template match="/">{    <xsl:apply-templates select="*"/>}    </xsl:template>      <!-- Object or Element Property-->    <xsl:template match="*">    "<xsl:value-of select="name()"/>" : <xsl:call-template name="Properties"/>                                         </xsl:template>                                           <!-- Array Element -->                                         <xsl:template match="*" mode="ArrayElement">                                         <xsl:call-template name="Properties"/>                                         </xsl:template>                                           <!-- Object Properties -->                                         <xsl:template name="Properties">                                         <xsl:variable name="childName" select="name(*[1])"/>                                         <xsl:choose>                                         <xsl:when test="not(*|@*)">"<xsl:value-of select="."/>"</xsl:when>                                         <xsl:when test="count(*[name()=$childName]) > 1">{ "<xsl:value-of select="$childName"/>" :[<xsl:apply-templates select="*" mode="ArrayElement"/>] }</xsl:when>                                         <xsl:otherwise>{                                           <xsl:apply-templates select="@*"/>                                             <xsl:apply-templates select="*"/>                                         }</xsl:otherwise>  </xsl:choose>  <xsl:if test="following-sibling::*">,</xsl:if>  </xsl:template>    <!-- Attribute Property -->  <xsl:template match="@*">"<xsl:value-of select="name()"/>" : "<xsl:value-of select="."/>",    </xsl:template>      </xsl:stylesheet>    

But the namespaces are removed in this . How can I edit the XSL file to convert to "ietf-restconf:notification" in JSON?

No comments:

Post a Comment