Re: [xsl] Re:XPathAPI: How to associate namespaces

Subject: Re: [xsl] Re:XPathAPI: How to associate namespaces
From: Torsten Schlabach <TSchlabach@xxxxxxx>
Date: Wed, 7 May 2003 12:47:58 +0200 (MEST)

sorry, I had gotten your 2nd e-mail before I got this one. This is why I did
not know what you meant.
Now it becomes clear to me; thank you. The original problem is much less
trivial than it appeared at first, but you'll run into this in case you start
using an XHTML document written by any compliant XHTML editor as this will have
exactly the characteristics I have described (default namespace, not

I will make up my mind which approach I will follow.

Just a side question to standards in general and namespaces in particular:
Is there any rule stating that a certain namespace URI (i.e. has to use a specific prefix i.e. xhtml)? Are namespace URIs sort
of "free form" anyway or where can I find the rules how to for example
construct my own namespace. There should be a way to avoid conflicting prefixes,
shouldn't it?

Anyway: Thank you for your time. You really helped my and probably the
Cocoon project as well.


> (Apologies if this is a repost; I've been having some trouble convincing 
> my mail system not to send HTML.)
> 1) XPath 1.0's syntax doesn't support default namespaces. To indicate a 
> namespaced node, you *must* use a prefix in your XPath. A name without a 
> prefix is taken as meaning you wand to find nodes which are in _no_ 
> namespace. (There is a proposal to fix this in XPath 2.0.)
> 2) You also have to provide a binding from those prefixes to the namespace
> URIs they represent. This is not standardized in XPath 1.0. (There is a 
> proposal to fix this in XPath 2.0.) Xalan's XPathAPI class offers three 
> options, via different versions of the function calls:
> a) If you just pass in context node and the XPath, we will attempt to 
> resolve prefixes in terms of namespaces known at the context node. As 
> noted above, this does not include the default namespace; you'd need to 
> have an explicit prefix bound to that same URI. (This can be considered a 
> shorthand for option b.)
> b) If you pass in context node, XPath, and a "namespace context node", we 
> will attempt to resolve prefixes in terms of namespaces known at the 
> namespace context node. Same issues as above.
> c) You can write a class implementing the PrefixResolver interface, and 
> pass it into XPathAPI in place of the namespace context node. In fact, the
> above two are implemented using an internal implementation of that 
> interface. Again, this doesn't free you from needing to use a prefix in 
> your XPath, but it does give you more flexibility in deciding how to 
> handle it. You could base your solution on ours, or just look in a static 
> table of prefix-to-URI bindings, or do whatever else seems appropriate.
> Note that this lookup should occur only *once*. If your default prefix 
> changes five times along the course of your XPath, you may in fact need 
> five separate prefixes to express that.
> See 
> for details of how to use these Xalan features.
> ______________________________________
> Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more. 
> "may'ron DaroQbe'chugh vaj bIrIQbej"  ("Put down the squeezebox and nobody
> gets hurt.")
>  XSL-List info and archive:

 XSL-List info and archive:

Current Thread