Project

Profile

Help

finding a prefix for a namespace inXPath 2.0

Added by Anonymous almost 18 years ago

Legacy ID: #4139162 Legacy Poster: Joseph Thomas-Kerr (jak09)

Hi, I'm writing an xslt 2 stylesheet, and I want to find a prefix declared by my source document for a particular namespace. The namespace axis lets you do it seemingly without too much hassle (where $namespace is the one I am trying to retrieve a prefix for): namespace::*[.=$namespace]/name()[1] However, the namespace axis is deprecated in XPath 2.0. Reading the spec it appears to have been replaced by in-scope-prefixes() and namespace-for-prefix(). While it would be possible to retrieve all of the in-scope-prefixes and then repetitively test whether the namespace for each matches the one I am after, this seems to be a rather cumbersome operation. (although I realise that this is exactly what the namespace axis syntax is specifying, its syntax is much simpler). Have I missed something? Is there a simpler way to do this? Regards, Joe.


Replies (2)

RE: finding a prefix for a namespace inXPath - Added by Anonymous almost 18 years ago

Legacy ID: #4139176 Legacy Poster: Michael Kay (mhkay)

Personally, I find the namespace axis a very useful mechanism and I have no intention of dropping it from Saxon. However, it's true that if you want guaranteed interoperability across XSLT 2.0 processors you have to use the new functions: in-scope-prefixes($e)[namespace-for-prefix(., $e) eq $namespace][1] The reason the namespace axis was deprecated was that some implementors found it difficult to implement efficiently. I've always thought that was a very poor justification. Michael Kay http://www.saxonica.com/

RE: finding a prefix for a namespace inXPath - Added by Anonymous almost 18 years ago

Legacy ID: #4139179 Legacy Poster: Joseph Thomas-Kerr (jak09)

"The reason the namespace axis was deprecated was that some implementors found it difficult to implement efficiently. I've always thought that was a very poor justification." Yes, this is a very odd reason for a standards body to deprecate something. Thanks for your lightning fast response, by the way! Joe.

    (1-2/2)

    Please register to reply