Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2518

Xalan inserts spurious xmlns attributes in elements with targetNamespace attributes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.7.1
    • None
    • Xalan
    • Security Level: No security risk; visible to anyone (Ordinary problems in Xalan projects. Anybody can view the issue.)
    • None
    • Observed on RedHat 5.1 and Windows XP.

    Description

      Under certain conditions, when Xalan encounters a element with a targetNamespace but no "xmlns" attribute, it will add an xmlns attribute even if the attribute is not required.

      The following example (which is a simple XSLT to change the default namespace of an XML document) demonstrates the problem:

      Input:

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <root xmlns="http://www.alcatel-lucent.com/1">
      <xsd:schema
      xmlns:a="http://www.alcatel-lucent.com/schema-a"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://www.alcatel-lucent.com/schema-a">
      <xsd:complexType name="MyType">
      <xsd:complexContent>
      <xsd:sequence>
      <xsd:element name="name" type="xsd:string"/>
      </xsd:sequence>
      </xsd:complexContent>
      </xsd:complexType>
      <xsd:element name="element" type="a:MyType"/>
      </xsd:schema>
      <testElementFromNs1/>
      </root>

      XSLT:

      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:ns1="http://www.alcatel-lucent.com/1"
      xmlns="http://www.alcatel-lucent.com/2"
      version="1.0"
      exclude-result-prefixes="ns1">

      <xsl:output method="xml" indent="yes"/>

      <!-- Copy all objects and their contents -->
      <xsl:template match="node()|@*">
      <xsl:copy>
      <xsl:apply-templates select="node()|@*" />
      </xsl:copy>
      </xsl:template>

      <!--
      Copy all objects from ns1, but change their namespace to the new namespace.
      By only using the local name of the element, we effectively assign it to
      the "xmlns=" namespace declared in the document's root node.
      -->
      <xsl:template match="ns1:*">
      <xsl:element name="

      {local-name()}

      ">
      <xsl:apply-templates select="node()|@*"/>
      </xsl:element>
      </xsl:template>

      </xsl:stylesheet>

      The output "xsd:schema" element will have 'xmlns="http://www.alcatel-lucent.com/1"' added to its list of attributes (especially strange since no child elements reference the namespace, and the namespace is the "old" namespace).

      In our application this is causing problems because we have a schema embedded as part of a configuration file. When we try to run the configuration file through an XSLT, these extra xmlns attributes are added to various schema elements. When we later try to extract the schema, the extra xmlns attributes are not necessarily understood by the client trying to use the schema.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jasonwalton Jason Walton
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: