0

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.

1
  • That apim prefix isn't in your XSLT, so it must come from your input XML. We'll need to see the input XML to figure out where each namespace comes from and what context the given element is in. Commented May 11, 2017 at 9:46

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.