Re: [xml] xsltproc and redundant namespace prefix declarations



On Sun, Mar 16, 2003 at 07:33:37PM +1100, Cameron McCormack wrote:
Hi everyone.

I'm using xsltproc, and one thing I find is that it sticks in xmlns
attributes into my output documents when they are not needed.
[...]
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:blah="urn:blah:1" xmlns="urn:blah:1">
    <xsl:template match="blah:test">
      <replacement/>
    </xsl:template>
[...]
then I get an output document like this:

  <?xml version="1.0"?>
  <in xmlns="urn:blah:1">
    <replacement xmlns:blah="urn:blah:1"/>
  </in>

The xmlns:blah="urn:blah:1" is not really needed.  The namespace prefix
was introduced in the .xsl file just so I could refer to the <test/>
element.  Is there any way to get xsltproc to leave the prefix
declaration out?

   That is normal actually. There is no way the processor can assert that
that mapping might not be used in textual content like QName value in attribute
content or element text. As a result the XSLT spec forces to propagate any
namespace in scope at the point of the element dumped. The way to avoid it
is to use exclude-result-prefixes="blah"
   http://www.w3.org/TR/xslt#stylesheet-element

As an aside, why doesn't the element referenced in the match attribute
of <xsl:template/> use the default namespace?

  Because XPath expressions do not operate with default namespaces,
basically the XPath expression "foo" matches only nodes of name
foo in no namespaces. If you want to match a namespaced node you must
use a namespace prefix or a construct based on XPath functions 
local-name() and namespace-uri()
  http://www.w3.org/TR/xpath#function-local-name
  http://www.w3.org/TR/xpath#function-namespace-uri

  Not bugs, just conformance to the specs, and nothing replace learning
the specs !

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]