Reputation: 42997
I am pretty new in WSO2 ESB and I have not experience with xslt (I think that it should be more related to xslt than WSO2).
Can you help me to understand deeply what it does this .xslt template file? It should remove namespace from my XML but how exactly works?
<?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="@*|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|node()">
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*|node()">
</xsl:apply-templates>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
It should remove the xmlns="http://ws.wso2.org/dataservice" namespace from an XML like this:
<?xml version="1.0" encoding="UTF-8"?>
<transfer xmlns="http://ws.wso2.org/dataservice">
<providerpid>00AB40</providerpid>
<recipientpid>00AD12</recipientpid>
<symbol>SMTA1234</symbol>
<type>SMTA</type>
<materials>
<doi>10.0155/1463</doi>
<doi>10.0155/1464</doi>
</materials>
</transfer>
Upvotes: 0
Views: 67
Reputation: 163468
There are three instructions in XSLT to create new elements:
literal result elements: for example <xyz>....</xyz>
. With these, the new element gets all the namespaces declared in the containing stylesheet, other than any that are excluded using exclude-result-prefixes (and those implicitly excluded, like the XSLT namespace).
xsl:copy. Here, the new element gets all the namespaces from the relevant element in the source document. In XSLT 2.0/3.0 you can prevent this with the copy-namespaces attribute: but even then, the element name won't change, so if it is in a namespace, it will stay in that namespace.
xsl:element. Here the new element gets only the namespaces actually needed for the (new) element name and any namespaced attribute names. In this example the new element isn't in a namespace so no namespace declarations are added.
This stylesheet is using xsl:element to ensure that the only namespaces on the new element are those that are actually needed.
Upvotes: 0
Reputation: 3435
namespace is removed by xslt because it is not declare in xslt, if you want to preserve namespace than change
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
to
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://ws.wso2.org/dataservice">
it will retain your namespace
Upvotes: 1