Re: [xsl] How to force the XSLT processor to retain a namespace declaration on the root element?

Subject: Re: [xsl] How to force the XSLT processor to retain a namespace declaration on the root element?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 24 Mar 2022 19:00:32 -0000
On 24.03.2022 19:56, Roger L Costello costello@xxxxxxxxx wrote:
Hi Folks,

I have an XSLT program that processes an XML Schema.

I have a template rule for the root element (xs:schema)

<xsl:template match="xs:schema">
     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
                          xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/";>
         <xsl:apply-templates/>
     </xs:schema>
</xsl:template>

Notice that the template rule outputs the xs:schema element with two
namespace declarations: one for the XMLSchema namespace and one for the DFDL
namespace.

When I run the XSLT program, I get this output:


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
      ...
</xs:schema>

Notice that the DFDL namespace declaration is gone. The XSLT processor has
moved the declaration down to where the dfdl prefix is used. That is a problem
because the DFDL processor insists on having the DFDL namespace declared on
the root element (xs:schema) and the DFDL processor simply will not run unless
it is there.


So which XSLT processor does that? Or do you happen to use exclude-result-prefixes="dfdl"?


How do I force the XSLT processor to retain the DFDL namespace declaration
on the root element?


If you need that namespace declaration in scope for the root of the literal result element tree and any other elements you could also consider moving it to the xsl:stylesheet or xsl:transform root of the stylesheet.

Current Thread