Reputation: 3
I would like to remove a namespace with a specific value from all the elements that have it. I am looking for XSLT transformation for it
As shown below , i need to remove xmlns="NS_647" from the elements that contain it
Input XML
<COSR xmlns="TEST_NS1" >
<ORM_O01.PATIENT xmlns="NS_647" >
<PID>
<PID.1>1</PID.1>
</PID>
</ORM_O01.PATIENT>
</COSR>
Output
<COSR xmlns="TEST_NS1" >
<ORM_O01.PATIENT >
<PID>
<PID.1>1</PID.1>
</PID>
</ORM_O01.PATIENT>
</COSR>
Upvotes: 0
Views: 1201
Reputation: 163458
XSLT operates on a tree of nodes described by the XDM data model, and not on raw lexical XML. In the XDM tree representation of your input, the xmlns="NS_647"
is not present as an attribute node. Instead, the namespace declaration has two effects:
So what you actually want to do in your transformation is to change the relevant elements to be in namespace "TEST_NS1"
rather than in "NS_647"
. You can achieve that with the template rule:
<xsl:template match="*[namespace-uri()='NS_647']">
<xsl:element name="{local-name(.)}" namespace="TEST_NS1">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
Upvotes: 4
Reputation: 2852
Try this xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0