Given the following XML:
<?xml version="1.0" encoding="utf-8"?>
<Store>
<p1:Document xmlns:p1="urn:iso:std:iso:xyz">
<p1:Class>
Hello
<p1:Type>
Now
</p1:Type>
</p1:Class>
<!-- more elements -->
</p1:Document>
</Store>
How would I write an XSLT to transform the Document element in the following way:
<?xml version="1.0" encoding="utf-8"?>
<Store>
<Document xmlns="urn:iso:std:iso:123>
<Class>
Hello
<Type>
Now
</Type>
</Class>
<!-- more elements -->
</Document>
</Store>
As you can see, I need to copy the Document element, but I need to strip all of its namespace declarations and prefixes, and then add a new namespace declaration.
How would I accomplish this in XSL?
The solution is a variation of an answer like
"How to remove namespace prefix leaving namespace value (XSLT)?" and the application of a template with a
mode
attribute to process only the children of theDocument
element.If you still get unwanted namespaces in the output document, follow the instructions in the answer "XSL: Avoid exporting namespace definitions to resulting XML documents" and add
exclude-result-prefixes="ns0 ns1"
to yourxsl:stylesheet
element. This should get rid of some unwanted namespaces quite easily.If this doesn't help, you need to create a new question with a Minimal, Complete and Verifiable Example containing all relevant aspects.
Next time at least try to solve the problem on your own by searching this site for answers.