title: Reference to undeclared namespace prefix: 'json'. while renaming xml attibute with xslt
body: <blockquote>
    <p>Updated with Minimal, Complete and Verifiable information thanks <a href="https://stackoverflow.com/users/290085/kjhughes">@Kenneth</a> for drawing my attention.</p>
  </blockquote>
  
  <p>So, I'm trying to rename an xml attribute using xslt, but I keep getting this error message: </p>
  
  <blockquote>
    <p>Reference to undeclared namespace prefix: 'json'.</p>
  </blockquote>
  
  <ol>
  <li><p>This is my source xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;data&gt;
    &lt;code&gt;SO000009&lt;/code&gt;
    &lt;businessPartner&gt;70833A356B9A428CBDDCD2A76A49681F&lt;/businessPartner&gt;
    &lt;startDateTime&gt;2018-01-25T15:24:27Z&lt;/startDateTime&gt;
    &lt;subject&gt;Test&lt;/subject&gt;
    &lt;equipments jsonArray="true"&gt;80202&lt;/equipments&gt;
  &lt;/data&gt;
  </code></pre></li>
  <li><p>This is how I want the xml to be:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;data xmlns:json="http://james.newtonking.com/projects/json"&gt;
    &lt;code&gt;SO000009&lt;/code&gt;
    &lt;businessPartner&gt;70833A356B9A428CBDDCD2A76A49681F&lt;/businessPartner&gt;
    &lt;startDateTime&gt;2018-01-25T15:24:27Z&lt;/startDateTime&gt;
    &lt;subject&gt;Test&lt;/subject&gt;
    &lt;equipments json:Array="true"&gt;80202&lt;/equipments&gt;
  &lt;/data&gt;
  </code></pre></li>
  <li><p>And this is my xslt:</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output indent="yes"/&gt;
    &lt;xsl:template match="/data"&gt;
      &lt;data xmlns:json="http://james.newtonking.com/projects/json"&gt;
        &lt;xsl:apply-templates select="node()|@*" /&gt;
      &lt;/data&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="@*"&gt;
      &lt;xsl:attribute name="{local-name()}"&gt;
        &lt;xsl:value-of select="." /&gt;
      &lt;/xsl:attribute&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="node()"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="node()|@*" /&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="@jsonArray"&gt;
      &lt;xsl:attribute name="json:Array"&gt;
        &lt;xsl:value-of select="."/&gt;
      &lt;/xsl:attribute&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre></li>
  </ol>
  
  <p>When I'm trying to convert my xml, I keep getting this message:</p>
  
  <blockquote>
    <p>Error occurred while compiling stylesheet 'CS_jsonArray.xslt'.</p>
    
    <p>Code:   0x80004005</p>
    
    <p>Reference to undeclared namespace prefix: 'json'.</p>
  </blockquote>