-1

Updated with Minimal, Complete and Verifiable information thanks @Kenneth for drawing my attention.

So, I'm trying to rename an xml attribute using xslt, but I keep getting this error message:

Reference to undeclared namespace prefix: 'json'.

  1. This is my source xml:

    <?xml version="1.0" encoding="utf-8"?>
    <data>
      <code>SO000009</code>
      <businessPartner>70833A356B9A428CBDDCD2A76A49681F</businessPartner>
      <startDateTime>2018-01-25T15:24:27Z</startDateTime>
      <subject>Test</subject>
      <equipments jsonArray="true">80202</equipments>
    </data>
    
  2. This is how I want the xml to be:

    <?xml version="1.0" encoding="utf-16"?>
    <data xmlns:json="http://james.newtonking.com/projects/json">
      <code>SO000009</code>
      <businessPartner>70833A356B9A428CBDDCD2A76A49681F</businessPartner>
      <startDateTime>2018-01-25T15:24:27Z</startDateTime>
      <subject>Test</subject>
      <equipments json:Array="true">80202</equipments>
    </data>
    
  3. And this is my xslt:

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output indent="yes"/>
      <xsl:template match="/data">
        <data xmlns:json="http://james.newtonking.com/projects/json">
          <xsl:apply-templates select="node()|@*" />
        </data>
      </xsl:template>
    
      <xsl:template match="@*">
        <xsl:attribute name="{local-name()}">
          <xsl:value-of select="." />
        </xsl:attribute>
      </xsl:template>
    
      <xsl:template match="node()">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*" />
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="@jsonArray">
        <xsl:attribute name="json:Array">
          <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:template>
    </xsl:stylesheet>
    

When I'm trying to convert my xml, I keep getting this message:

Error occurred while compiling stylesheet 'CS_jsonArray.xslt'.

Code: 0x80004005

Reference to undeclared namespace prefix: 'json'.

Community
  • 1
  • 1
Job
  • 86
  • 6
  • **Never post code and XML as images**. Use text formatted as code. Click the [edit] link and correct. Be sure to include a [mcve]. – kjhughes Nov 24 '16 at 18:41
  • *When I'm trying to convert my xml*...and where is this trial? – Parfait Nov 24 '16 at 21:18
  • The solution is to declare the undeclared namespace prefix: 'json'. You did not show us your stylesheet, but you can find many examples if you search for them. – michael.hor257k Nov 24 '16 at 22:46

1 Answers1

0

After looking in the 'Related' sidebar, I did found the answer to my own question.

XSL transformation - Namespace prefix undeclared

So for those who have a same issue, be sure the namespace you want to change the attribute names for, is also in the xslt tag itself...

This is how my xslt started:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>...

This is how I changed it:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:json="http://james.newtonking.com/projects/json">
  <xsl:output indent="yes"/>...
Community
  • 1
  • 1
Job
  • 86
  • 6