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

Subject: [xsl] How to force the XSLT processor to retain a namespace declaration on the root element?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 24 Mar 2022 18:56:19 -0000
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.

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

/Roger

Current Thread