I would like to create xml like this:
<rns:RootElement xmlns:rns="urn:root-element" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:root-element root-element.xsd">
<rns:DocumentWrapper>
<ins:InnerDoc xmlns:ins="urn:inner-doc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:inner-doc inner-doc.xsd">
<ins:Value>Some text</ins:Value>
</ins:InnerDoc>
</rns:DocumentWrapper>
</rns:RootElement>
With this template:
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<rns:RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rns="urn:root-element"
xsi:schemaLocation="urn:root-element root-element.xsd">
<rns:DocumentWrapper>
<ins:InnerDoc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ins="urn:inner-doc"
xsi:schemaLocation="urn:inner-doc inner-doc.xsd">
<ins:Value><xsl:value-of select="//*[local-name()='SomeNode']"/></ins:Value>
</ins:InnerDoc>
</rns:DocumentWrapper>
</rns:RootElement>
</xsl:template>
But instead of result that i wanted this template gave me a little bit different result:
<rns:RootElement xmlns:rns="urn:root-element" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:root-element root-element.xsd">
<rns:DocumentWrapper>
<ins:InnerDoc xmlns:ins="urn:inner-doc" xsi:schemaLocation="urn:inner-doc inner-doc.xsd">
<ins:Value>Some text</ins:Value>
</ins:InnerDoc>
</rns:DocumentWrapper>
</rns:RootElement>
As you can see, in transformation result, InnerDoc element lacks definition of xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" namespace, is there any way to prevent missing of this namespace?
ins
namespace declaration doesn't do anything. Any conformant XML processor will recognize that theins
namespace declaration on the root element also applies to thisins:InnerDoc
element. Any conformant XSL processor that moves the location of thisins:InnerDoc
element to some other location, where the declaration on the root element doesn't apply, will also add in the namespace declaration as needed. – Eiríkr Útlendi