1

Thanks to Stack Overflow and @michael.hor257k I was able to update namespaces successfully in my XML Document.

Now, there is only one problem.
My SAP System couldn't understand a couple of fields from XSD and thus added its own namespace to accommodate to the XML Schema.

This is solvable through SAP, but we don't have that software(SPROXY) installed yet.

So, I have to achieve this using XSLT 1.0.

My original XML was:

    <?xml version="1.0" encoding="UTF-8"?>

<n0:eCPR xmlns:prx="urn:sap.com:proxy:DV4:/1SAI/TAS1F59A417878D36573F1D:700:2013/05/24" xmlns:n0="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">

<n0:employees>
  <n0:employee>
    <n0:name id="20019768">Paul John</n0:name>
</n0:employee>
</n0:employees>
</n0:eCPR>

And the XSLT Used to achieve the required output below:

   <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:strip-space elements="*"/>

   <xsl:template match="*">
     <xsl:element name="CPR:{local-name()}">
    <xsl:copy-of select="@*"/>
     <xsl:apply-templates/>
   </xsl:element>
   </xsl:template>

After updating with the current namespace my XML(Where the error is) Looks like

<?xml version="1.0" encoding="UTF-8"?>
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
 <CPR:projectInfo>
  <CPR:awardingBody xmlns:asx="http://www.sap.com/abapxml" asx:root=""/>
  <CPR:contractAgencyID xmlns:asx="http://www.sap.com/abapxml" asx:root=""/>
  <CPR:contractAgency/>
  <CPR:projectName xmlns:asx="http://www.sap.com/abapxml" asx:root=""/>
  <CPR:projectID/>
  <CPR:awardingBodyID/>
  <CPR:projectNum/>
  <CPR:contractID/>

So, the nodes awardingBody,contractAgencyID and Project Name are the fields which couldn't got properly converted by the system.( The nodes with xmlns:asx namespace )

I need to remove these namespaces. Is it possible through XSLT. Condition: Remove namespace of only those entries whose namespace is http://www.sap.com/abapxml or I can provide a name of nodes(as they are fixed)

What the ideal structure should be:

<?xml version="1.0" encoding="UTF-8"?>
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
 <CPR:projectInfo>
  <CPR:awardingBody/>
  <CPR:contractAgencyID />
  <CPR:contractAgency/>
  <CPR:projectName/>
  <CPR:projectID/>
  <CPR:awardingBodyID/>
  <CPR:projectNum/>
  <CPR:contractID/>

Thanks

5
  • Please specify XSLT 1.0 or 2.0. Commented Dec 2, 2016 at 22:42
  • @MichaelKay XSLT 1.0 Commented Dec 3, 2016 at 1:22
  • This is very confusing. Is the first XML the input to the transformation? Based on your previous 2 questions on this, I suspect it is the output. Please show the input or clarify. Commented Dec 3, 2016 at 6:50
  • @michael.hor257k Yes, after your help, i was able to product the first XML. Now, i wanted the first XML to be the input. But, we can use the original XML also. I will update the post with original XML and current XSLT which will help you Commented Dec 3, 2016 at 6:59
  • Please show the original XML that produces the output you show us. The one that has the awardingBody, contractAgencyID and Project Name elements with the root attribute. The input you show us could not produce the output you claim. Commented Dec 3, 2016 at 7:17

1 Answer 1

1

I am guessing (!) that your original XML actually looks something like this:

XML

<n0:eCPR xmlns:n0="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd" xmlns:asx="http://www.sap.com/abapxml">
    <n0:projectInfo>
        <n0:awardingBody asx:root=""/>
        <n0:contractAgencyID asx:root=""/>
        <n0:contractAgency/>
        <n0:projectName asx:root=""/>
        <n0:projectID/>
        <n0:awardingBodyID/>
        <n0:projectNum/>
        <n0:contractID/>
    </n0:projectInfo>
</n0:eCPR>

In order to get the requested output - i.e. without copying the asx:root attributes - you need to do:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="*">
    <xsl:element name="CPR:{local-name()}">
    <xsl:copy-of select="@*[not(namespace-uri()='http://www.sap.com/abapxml')]"/>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>

Or perhaps do:

<xsl:copy-of select="@*[not(namespace-uri())]"/>

to remove any attributes that aren't in no-namespace.

Sign up to request clarification or add additional context in comments.

1 Comment

@micheal Perfect.. The whole problem is fixed. Thanks for all your replies and clarifications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.