XML without namespace

I need to extract XML from an envelope. But I can’t get my intended result. I need to get rid of namespaces in my release.

My details:

<ns1:input xmlns:ns1="http://mysapmle.org/" xmlns="http://othersample.org/"> <sample> <inner tc="5">Test</inner> <routine>Always</routine> </sample> </ns1:input> 

My expected result:

 <sample> <inner tc="5">Test</inner> <routine>Always</routine> </sample> 

My actual output is:

  <sample xmlns="http://othersample.org/"> <inner tc="5">Test</inner> <routine>Always</routine> </sample> 

My XSLT:

 <xsl:output omit-xml-declaration="yes" indent="yes" /> <xsl:template match="/"> <xsl:copy copy-namespaces="no"> <xsl:apply-templates select="//sample" /> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy copy-namespaces="no"> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> 

Please, help.

+4
source share
1 answer

This should work to remove namespaces:

 <xsl:output omit-xml-declaration="yes" indent="yes" /> <xsl:template match="/"> <xsl:apply-templates select="*/*" /> </xsl:template> <xsl:template match="@*"> <xsl:attribute name="{local-name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> <xsl:template match="*"> <xsl:element name="{local-name()}"> <xsl:apply-templates select="@* | node()" /> </xsl:element> </xsl:template> 

But I somewhat doubt that you need to do this. If the XML to which you add this uses the same namespace, and that namespace that contains the XML, it should not matter that this XML has namespace declarations in it.

+2
source

All Articles