Bjoern Hoehrmann skrev:
* Tim Hallwyl wrote in comp.text.xml:
Is it possible to resolve a namspace-uri to the corresponding prefix
using XPath 1.0?
For example if I have obtained a namespace-uri a an element in one
document and I need to know the prefix used at some element in an other
document, using XPath?
I am not really sure what you are asking, but keep in mind that there
might not be a declared prefix for some namespace name,
I am sorry I was not clear on this, but I am guaranteed that the
namespace-uri is declared in both documents.
the names are generally arbitrary, the same prefix may be used for
different name- space names in different places in one document, and
there may be many prefixes for a given namespace name.
Exactly. Let me reformulate my question: Provided an XPath to some
element and a namespace-uri that somehow is guaranteed to be declared
with a prefix for the element that the XPath points at, how do get that
prefix?
In
http://www.w3.org/TR/xpath you can read up on the namespace axis,
namespace nodes, and the name() function, which might give you what you
are looking for.
Thank you for the pointers. I have been there before, but I just could
not get it working. It turns out I made the mistake of trying with the
the default namespace uri -- my bad. So to answer my own question, based
on your pointers:
Given an XPath to some element, e.g.
/bpel
rocess/bpel:sequence/bpel:reply
and a namespace-uri, e.g.
http://schemas.xmlsoap.org/wsdl/
I can get the (first) prefix declared using:
name(/bpel
rocess/bpel:sequence/bpel:reply/namespace::*[self::node() =
'
http://beepell.com/samples/proxy/definitions'][1])
If anyone know a more elegant method, let me know. Thanks.