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

Namespace nodes are generated for empty namespace

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Duplicate
    • 2.7
    • 2.7.1
    • Xalan
    • None

    Description

      When elements in the empty namespace (no namespace) are descendants of nodes in some other unprefixed namespace, in Xalan is reporting namespace nodes for the default, empty namespace – i.e., it is saying there are namespace nodes that have an empty string-value and empty local-name corresponding to xmlns="".

      The first paragraph of XPath 1.0 section 5.4 and the behavior of other processors indicates such nodes are not part of the XPath data model. That is, it is impossible to have a namespace node whose string-value is an empty string; namespace nodes only indicate what non-empty namespaces are in scope.

      The presence of the extra nodes is redundant; it's implicit that the element is in no namespace if it has no namespace nodes with an empty local-name.

      The following example demonstrates. The stylesheet serializes the 'e' elements, showing their namespace node information. Elements 1-4 have extraneous namespace nodes. The others are fine.

      xmlns.xml
      ==========
      <data>

      <group xmlns="http://example.com/foo">

      <!-e elements in empty namespace, ancestors in non-empty namespace->
      <group xmlns="">
      <e>one</e>
      <e>two</e>
      <group>
      <e>three</e>
      <e>four</e>
      </group>
      </group>

      <!-e elements in same non-empty namespace as ancestor->
      <group>
      <e>five</e>
      <group>
      <e>six</e>
      </group>
      </group>
      </group>

      <!-e elements and ancestors in non-empty namespace->
      <group>
      <e>seven</e>
      </group>

      </data>

      xmlns.xsl
      ==========
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

      <xsl:template match="/">
      <xsl:apply-templates select="//*[local-name()='e']"/>
      </xsl:template>

      <xsl:template match="*[local-name()='e']">
      <Element content="

      {.}

      ">
      <xsl:for-each select="namespace::*">
      <Namespace prefix="

      {local-name()}

      ">
      <xsl:value-of select="."/>
      </Namespace>
      </xsl:for-each>
      </Element>
      </xsl:template>

      </xsl:stylesheet>

      expected
      =========
      <?xml version="1.0" encoding="UTF-8"?>
      <Element content="one">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      </Element>
      <Element content="two">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      </Element>
      <Element content="three">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      </Element>
      <Element content="four">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      </Element>
      <Element content="five">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      <Namespace prefix="">http://example.com/foo</Namespace>
      </Element>
      <Element content="six">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      <Namespace prefix="">http://example.com/foo</Namespace>
      </Element>
      <Element content="seven">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      </Element>

      actual (with Xalan-J 2.7.0)
      =======================
      <?xml version="1.0" encoding="UTF-8"?>
      <Element content="one">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      <Namespace prefix=""/>
      </Element>
      <Element content="two">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      <Namespace prefix=""/>
      </Element>
      <Element content="three">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      <Namespace prefix=""/>
      </Element>
      <Element content="four">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      <Namespace prefix=""/>
      </Element>
      <Element content="five">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      <Namespace prefix="">http://example.com/foo</Namespace>
      </Element>
      <Element content="six">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      <Namespace prefix="">http://example.com/foo</Namespace>
      </Element>
      <Element content="seven">
      <Namespace prefix="xml">http://www.w3.org/XML/1998/namespace</Namespace>
      </Element>

      I have a real-world stylesheet that serializes elements as character data, in XML syntax, in an HTML textarea. I rely on the namespace axis to faithfully report what namespaces are in scope. I'd like to not have to go out of my way to ignore extra namespace nodes in this one XSLT processor.

      Thanks for considering this issue.

      Attachments

        1. xmlns.xsl
          0.5 kB
          Mike Brown
        2. xmlns.xml
          0.5 kB
          Mike Brown
        3. xalan2334-tests.patch
          6 kB
          Kevin Cormier

        Issue Links

          Activity

            People

              dmarston@apache.org David Marston
              mike@skew.org Mike Brown
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: