title: XML to JSON with namespaces
body: <p>I am trying to convert XML with XML namespace to JSON data  using XSLT as shown below:</p>
  
  <p>Basically if the XML element has a node of the form element xmnls= "urn:ietf:params:xml:ns:yang:ietf-modulename" .                              The JSON translation should be                                                                   "ietf-modulename:element" as in example below</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;notification
      xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"&gt;
      &lt;event-time&gt;2013-12-21T00:01:00Z&lt;/event-time&gt;
      &lt;event&gt;
      &lt;event-class&gt;fault&lt;/event-class&gt;
      &lt;reporting-entity&gt;
      &lt;card&gt;Ethernet0&lt;/card&gt;
      &lt;/reporting-entity&gt;
      &lt;severity&gt;major&lt;/severity&gt;
      &lt;/event&gt;
   &lt;/notification&gt;
  
  JSON Conversion:
  
  {
  "ietf-restconf:notification": {
  "event-time": "2013-12-21T00:01:00Z",
  "event": {
  "event-class": "fault",
  "reporting-entity": { "card": "Ethernet0" },
  "severity": "major"
  }
  </code></pre>
  
  <p>Using the below xslt :</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="text"/&gt;
  
  &lt;xsl:template match="/"&gt;{
    &lt;xsl:apply-templates select="*"/&gt;}
    &lt;/xsl:template&gt;
  
    &lt;!-- Object or Element Property--&gt;
    &lt;xsl:template match="*"&gt;
    "&lt;xsl:value-of select="name()"/&gt;" : &lt;xsl:call-template name="Properties"/&gt;
                                         &lt;/xsl:template&gt;
  
                                         &lt;!-- Array Element --&gt;
                                         &lt;xsl:template match="*" mode="ArrayElement"&gt;
                                         &lt;xsl:call-template name="Properties"/&gt;
                                         &lt;/xsl:template&gt;
  
                                         &lt;!-- Object Properties --&gt;
                                         &lt;xsl:template name="Properties"&gt;
                                         &lt;xsl:variable name="childName" select="name(*[1])"/&gt;
                                         &lt;xsl:choose&gt;
                                         &lt;xsl:when test="not(*|@*)"&gt;"&lt;xsl:value-of select="."/&gt;"&lt;/xsl:when&gt;
                                         &lt;xsl:when test="count(*[name()=$childName]) &gt; 1"&gt;{ "&lt;xsl:value-of select="$childName"/&gt;" :[&lt;xsl:apply-templates select="*" mode="ArrayElement"/&gt;] }&lt;/xsl:when&gt;
                                         &lt;xsl:otherwise&gt;{
                                           &lt;xsl:apply-templates select="@*"/&gt;
                                             &lt;xsl:apply-templates select="*"/&gt;
                                         }&lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  &lt;xsl:if test="following-sibling::*"&gt;,&lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  
  &lt;!-- Attribute Property --&gt;
  &lt;xsl:template match="@*"&gt;"&lt;xsl:value-of select="name()"/&gt;" : "&lt;xsl:value-of select="."/&gt;",
    &lt;/xsl:template&gt;
      &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>But the namespaces are removed in this .
   How can I edit the XSL file to convert  to "ietf-restconf:notification" in JSON?</p>
  
  <p>Another example :</p>
  
  <pre><code>&lt;interfaces
  xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"&gt;
  &lt;interface&gt;
  &lt;name&gt;0/4&lt;/name&gt;
  &lt;type
  xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type"&gt;ianaift:ethernetCsmacd
  &lt;/type&gt;
  &lt;enabled&gt;false&lt;/enabled&gt;
  &lt;link-up-down-trap-enable&gt;enabled&lt;/link-up-down-trap-enable&gt;
  &lt;ipv4
  xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"&gt;
  &lt;enabled&gt;false&lt;/enabled&gt;
  &lt;/ipv4&gt;
  &lt;ipv6
  xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"&gt;
  &lt;enabled&gt;false&lt;/enabled&gt;
  &lt;mtu&gt;1500&lt;/mtu&gt;
  &lt;forwarding&gt;false&lt;/forwarding&gt;
  &lt;dup-addr-detect-transmits&gt;1&lt;/dup-addr-detect-transmits&gt;
  &lt;autoconf&gt;
  &lt;create-global-addresses&gt;false&lt;/create-global-addresses&gt;
  &lt;/autoconf&gt;
  &lt;/ipv6&gt;
  &lt;/interface&gt;
  &lt;/interfaces&gt; 
  </code></pre>
  
  <p>should map to                                                                           </p>
  
  <pre><code>    {"ietf-interfaces:interfaces": {
    "interface": {
      "name": "0/4",
      "iana-if-type:type": "ianaift:ethernetCsmacd
  ",
      "enabled": "false",
      "link-up-down-trap-enable": "enabled",
      "ietf-ip:ipv4": {
        "enabled": "false"
      },
      "ietf-ip:ipv6": {
        "enabled": "false",
        "mtu": "1500",
        "forwarding": "false",
        "dup-addr-detect-transmits": "1",
        "autoconf": {
          "create-global-addresses": "false"
        }
      }
    }
  }}
  </code></pre>