Reputation: 129
I have a problem.
Element Response must be without namespaces (They are defined root element).
Input XSLT:
<xsl:stylesheet
xpath-default-namespace="http://www.iata.org/IATA/EDIST"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:h="http://www.iata.org/IATA/EDIST"
version="1.0"
>
<xsl:template match="h:Response[not(h:OrderViewProcessing)]">
<Response xmlns="http://www.iata.org/IATA/EDIST">
<OrderViewProcessing>
<MarketingMessages>
<MarketingMessage>
<Text>
Error text
</Text>
</MarketingMessage>
</MarketingMessages>
</OrderViewProcessing>
<xsl:apply-templates/>
</Response>
</xsl:template>
</xsl:stylesheet>
Output XML:
<Response xmlns:h="http://www.iata.org/IATA/EDIST"
namespace="http://www.iata.org/IATA/EDIST">
<OrderViewProcessing>
<MarketingMessages>
<MarketingMessage>
<Text>
Error Text
</Text>
</MarketingMessage>
</MarketingMessages>
</OrderViewProcessing>
</Response>
I need like XML:
<Response>
<OrderViewProcessing>
<MarketingMessages>
<MarketingMessage>
<Text>
Error Text
</Text>
</MarketingMessage>
</MarketingMessages>
</OrderViewProcessing>
</Response>
If you remove xmlns = "http://www.iata.org/IATA/EDIST" in XSLT, then xmlns = "" in XML becomes empty.
Update
This problem solved in this way:
<xsl:template match="h:Response[not(h:OrderViewProcessing)]">
<xsl:element name="Response" namespace="http://www.iata.org/IATA/EDIST">
<xsl:element name="OrderViewProcessing" namespace="http://www.iata.org/IATA/EDIST">
<xsl:element name="MarketingMessages" namespace="http://www.iata.org/IATA/EDIST">
<xsl:element name="MarketingMessage" namespace="http://www.iata.org/IATA/EDIST">
<xsl:element name="Text" namespace="http://www.iata.org/IATA/EDIST">
Error text
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Probably, solution must be better.
Upvotes: 0
Views: 462
Reputation: 163262
You're using xpath-default-namespace and version="1.0", which looks inconsistent, since this attribute is defined only in XSLT 2.0. You always need to tell us which version of XSLT you are using.
You're explicitly creating the Response element in namespace "http://www.iata.org/IATA/EDIST"
though you say you want it to be in no namespace. Why are you doing this?
You say that your output has the attribute namespace="http://www.iata.org/IATA/EDIST"
but there is nothing in your XSLT that could conceivably generate this attribute. I think this must have been from some experimental variation of your XSLT.
In general, if you need to declare namespaces in the stylesheet and don't want them copied into the output, you should specify exclude-result-prefixes="#all"
on the xsl:stylesheet element. But I think there's a little bit more going on here that you haven't explained clearly.
Upvotes: 1