I have an input xml -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root xmlns="http://www.somenamespace">
<Child1>
<A>a</A>
<B>b</B>
</Child1>
<Child2>
<C>c</C>
<D>d</D>
</Child2>
</Root>
I want my output xml after transformation to remove the namespace from root and add it to Element Child1 instead like this-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<NewRoot>
<NewChild1 xmlns="http://www.somenamespace">
<A>a</A>
<B>b</B>
</NewChild1>
<NewChild2>
<C>c</C>
<D>d</D>
</NewChild2>
</NewRoot>
My xslt looks like-
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.somenamespace"
xmlns:test="http://www.somenamespace"
exclude-result-prefixes="test">
<xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8" standalone="yes"/>
<xsl:template match="/">
<NewRoot>
<xsl:apply-templates select="test:Root/test:Child1"/>
<xsl:apply-templates select="test:Root/test:Child2"/>
</NewRoot>
</xsl:template>
<xsl:template match="test:Root/test:Child1">
<NewChild1> <xsl:value-of select="current()"/> </NewChild1>
</xsl:template>
<xsl:template match="test:Root/test:Child2">
<NewChild2> <xsl:value-of select="current()"/> </NewChild2>
</xsl:template>
</xsl:stylesheet>
Currently this adds the namespace to the NewRoot element.
Child2branch from its namespace to no-namespace.http://www.somenamespaceis because of thexmlns="http://www.somenamespace"namespace declaration, which affects all literal result elements whose name is unprefixed.