Reputation: 29
I have the following root element of a big XML file:
<Interchange xmlns='http://www.e2b.no/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.e2b.no/XMLSchema Interchange'>
I need to get
<Interchange>
Please advice, Sorry, I will not give examples of my attempts I will use basic template:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:e2b='http://www.e2b.no/XMLSchema'>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<!-- copy everything as-is apart from exceptions below -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="e2b:Interchange">
<Interchange>
<xsl:apply-templates/>
</Interchange>
</xsl:template>
</xsl:stylesheet>
When I tested I accidentally sent big XML to input with the beginning:
<?xml version='1.0' encoding='ISO-8859-1'?>
<Interchange>
insted
<?xml version='1.0' encoding='ISO-8859-1'?>
<Interchange xmlns='http://www.e2b.no/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.e2b.no/XMLSchema Interchange'>
Because I answered positive on my previous question.
Please advice, any ideas.
Upvotes: 1
Views: 1877
Reputation: 167571
Use
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:e2b='http://www.e2b.no/XMLSchema'
exclude-result-prefixes="e2b">
<!-- copy everything as-is apart from exceptions below -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="e2b:*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="/e2b:Interchange">
<xsl:element name="{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
That approach is necessary to transform the element from the e2b
namespace to no namespace.
Upvotes: 2