Okay, I'll go point-by-point:

>First, you refer to XPath 2.5...
I meant section 2.5 XPath 1.0 spec,.

>Second, the 'two' element in my example is namespaced
You didn't show that. More on this at #5 below.

>Third, recommending that I read an O'Reilly book instead of the
>spec is a specious insult...
I don't see why. I was suggesting this because many people, not
necessarily you, get tripped up on XPath's non-use of the default
namespace, and the spec doesn't explain this well. The books spend
time on the point because it has emerged as a frequent point of
confusion.

>Fourth, I *STILL* have the problem that dom4j/jaxen does one thing,
>Xalan does another, the spec seems to support dom4j/jaxen...
Dave Bertoni's comments address the required behavior of an XSLT
processor such as Xalan. He also discusses the issue of XPath needing
to get namespace bindings from a containing environment.

>[5] Again, given: <a xmlns='b'><c d='f'/></a>
This example has one setting of the default namespace. If we make a
prefix visible for ease of discussion, it would be:
<z:a xmlns:z='b'><z:c d='f'/></z:a>

> //*[name()='a']/c/@d   ...should fail, in Xalan it works.
We'll use local-name() instead of name() to counteract the prefix.
In the latest XalanJ and XalanC, that expression gets no nodes, but
//*[local-name()='a']/*[local-name()='c']/@d
correctly gets the text in @d.
If you had an XSLT stylesheet that declared xmlns:z='b', then this
//z:a/z:c/@d
would get the text in @d, but
//z:a/c/@d
would get no nodes, because z:a has no children whose name is c
(un-namespaced), only children named z:c. This is the area that has
confused enough people that we put faq-11 on our FAQ page. I used
prefixes in the example to make it more visible, but the same is true
if the source XML is as you showed: c is in the "b" namespace.

Your original bug report said that the input data looked like this
<one xmlns="asdf">
  <two xmlns="qwer"/>
</one>
meaning that the default gets reset to different namespace URIs as
you get deeper in the tree. Then you said
>I am trying to use XPath to select nodes from a real document that has
>multiple namespaces that are beyond my control. I am not transforming
>the document...
If the data doesn't use prefixes but keeps changing the default
instead, you can plan on having many more troubles. In XPath, selecting
//a:one/q:two
would work if you could declare bindings for the a and q prefixes. You
could do that in the context of a transformation or by setting a
PrefixResolver and having prefixes in your select expression. That does
not force you to have prefixes in the source XML data.
.................David Marston
If the people creating the data have


Reply via email to