Replace and get rid of specific XML namespace

Here should go questions about transforming XML with XSLT and FOP.
michuk
Posts: 8
Joined: Tue Dec 11, 2007 1:52 pm

Replace and get rid of specific XML namespace

Post by michuk »

I have an XML file which uses mostly standard XML namespace (call it xml:standard) and some additional elements defined by a proprietary XSD which extends the standard one (call it xml:prop).

Now I need to create a XSLT that transforms the incoming XML with proprietary elements into a standard one, replacing the proprietary elements so that they fit into the standard schema (the details are not important here, I know how to implement the transformation).

The problem is that in the resulting XML, there are still references to the xml:prop namespace, namely:

<someStandardElement xmlns="standard-namespace" xmlns:prop="proprietary-namespace">

How to get rid of them in the proper way? I tried messing with <xsl:namespace-alias> using syntax like:

<xsl:namespace-alias stylesheet-prefix="prop" result-prefix="standard"/>
or
<xsl:namespace-alias stylesheet-prefix="prop" result-prefix="#"/>

but without success.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Replace and get rid of specific XML namespace

Post by sorin_ristache »

Hello,

Did you try the attribute

Code: Select all

exclude-result-prefixes="prop"
in the root element xsl:stylesheet?


Regards,
Sorin
michuk
Posts: 8
Joined: Tue Dec 11, 2007 1:52 pm

Re: Replace and get rid of specific XML namespace

Post by michuk »

sorin wrote:Hello,

Did you try the attribute

Code: Select all

exclude-result-prefixes="prop"
in the root element xsl:stylesheet?
Actually I did try that before but I only applied it to the child XSL (which actually included the prop elements). Now I applied it to the parent element but still no luck...
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Replace and get rid of specific XML namespace

Post by sorin_ristache »

Do you mean that the result contains the attribute xmlns:prop="proprietary-namespace"? Can you post an example of your XML file and XSLT file?


Regards,
Sorin
michuk
Posts: 8
Joined: Tue Dec 11, 2007 1:52 pm

Re: Replace and get rid of specific XML namespace

Post by michuk »

sorin wrote:Do you mean that the result contains the attribute xmlns:prop="proprietary-namespace"? Can you post an example of your XML file and XSLT file?
Regards,
Sorin
I'm afraid I can't post the xml/xslt pair since those are restricted for company my use.

Still I can show you the case in more detail.

The incoming file looks something like this:

<XML xsi:type="prop:SomeType" xmlns:prop="proprietary-namespace" xmlns="standard-namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<standard-element>
<non-standard-element>[...data...]</non-standard-element>
</standard-element>
[...lots of data...]
</XML>

I have 2 XSLT files:
do-generic.xsl - only handles and transforms the standard elements
do-specific.xsl (which imports do-generic.xsl) - transforms both standard elements and non-standard ones
I'm running the do-specific.xsl stylesheet on incoming XML file.

do-generic.xsl looks like like:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:standard="standard-namespace"
exclude-result-prefixes="prop">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
[..lots of templates...]
</xsl:stylesheet>

do-specific.xsl looks like like:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:standard="standard-namespace"
xmlns:prop="prop-namespace"
exclude-result-prefixes="prop">
<xsl:import href="do-generic.xslt"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
[..lots of templates...]
</xsl:stylesheet>

The templates mostly copy the XML, only in few cases there is actual transforming done.

And here is the result XML:
<XML xmlns:standard="standard-namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<standard-element xmlns="standard-namespace" xmlns:prop="proprietary-namespace">
</standard-element>
<different-standard-element>
[...data from the non-standard element...]
</different-standard-element>
[...lots of data...]
</XML>

Hope this is enough data. If you have any more questions, please ask.
Post Reply