[xsl] [Using xsltproc]: output of running XSLT is missing xmlns attributes

Subject: [xsl] [Using xsltproc]: output of running XSLT is missing xmlns attributes
From: "ohaya ohaya@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 May 2022 09:47:40 -0000
Hi,

I have an XML file:

<?xml version="1.0" encoding="UTF-8"?>
<exp:Export Version="3.0"
    xmlns:L7p="http://www.layer7tech.com/ws/policy";
    xmlns:exp="http://www.layer7tech.com/ws/policy/export"; xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy";>
    <exp:References/>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy"; xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy";>
        <wsp:All wsp:Usage="Required">
            <L7p:AuditAssertion>
                <L7p:Level stringValue="INFO"/>
            </L7p:AuditAssertion>
            <L7p:AuditDetailAssertion>
                <L7p:Detail stringValue="2222"/>
            </L7p:AuditDetailAssertion>
            <L7p:AuditDetailAssertion>
                <L7p:Detail stringValue="333"/>
                <L7p:Level stringValue="WARNING"/>
            </L7p:AuditDetailAssertion>
            <wsp:OneOrMore wsp:Usage="Required">
                <wsp:OneOrMore wsp:Usage="Required">
                    <L7p:AuditDetailAssertion>
                        <L7p:Detail stringValue="444"/>
                        <L7p:Level stringValue="FINE"/>
                    </L7p:AuditDetailAssertion>
                </wsp:OneOrMore>
                <wsp:OneOrMore wsp:Usage="Required">
                    <L7p:AuditDetailAssertion>
                        <L7p:Detail stringValue="555"/>
                        <L7p:Level stringValue="FINEST"/>
                    </L7p:AuditDetailAssertion>
                </wsp:OneOrMore>
            </wsp:OneOrMore>
        </wsp:All>
    </wsp:Policy>
</exp:Export>

and I want to remove all of the L7p:AuditDetailAssertion/L7p:Level elements.

I am using the xsltproc from Redhat 7 to run the XSLT.

Here's the XSLT that I am using:

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:L7p="http://www.layer7tech.com/ws/policy";
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  version="1.0">

  <xsl:output omit-xml-declaration="no" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <!-- TEMPLATE #1 -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <!-- TEMPLATE #2 -->
  <xsl:template match="L7p:AuditDetailAssertion/L7p:Level" />

</xsl:stylesheet>

and the output that I am getting is:

<?xml version="1.0"?>
<exp:Export xmlns:L7p="http://www.layer7tech.com/ws/policy"; xmlns:exp="http://www.layer7tech.com/ws/policy/export"; xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy"; Version="3.0">
  <exp:References/>
  <wsp:Policy>
    <wsp:All wsp:Usage="Required">
      <L7p:AuditAssertion>
        <L7p:Level stringValue="INFO"/>
      </L7p:AuditAssertion>
      <L7p:AuditDetailAssertion>
        <L7p:Detail stringValue="2222"/>
      </L7p:AuditDetailAssertion>
      <L7p:AuditDetailAssertion>
        <L7p:Detail stringValue="333"/>
      </L7p:AuditDetailAssertion>
      <wsp:OneOrMore wsp:Usage="Required">
        <wsp:OneOrMore wsp:Usage="Required">
          <L7p:AuditDetailAssertion>
            <L7p:Detail stringValue="444"/>
          </L7p:AuditDetailAssertion>
        </wsp:OneOrMore>
        <wsp:OneOrMore wsp:Usage="Required">
          <L7p:AuditDetailAssertion>
            <L7p:Detail stringValue="555"/>
          </L7p:AuditDetailAssertion>
        </wsp:OneOrMore>
      </wsp:OneOrMore>
    </wsp:All>
  </wsp:Policy>
</exp:Export>

Notice that in the output, the <wsp:Policy> is missing the two "xmlns" attributes, "xmlns:L7p" and "xmlns:wsp".

How can I get the XSLT to include those "xmlns" attributes on the <wsp:Policy> element?

Thanks,
Jim

Current Thread