Given this document:
<doc>
<head>
<someElementWithID id="X"/>
<someElementWithID id="Y"/>
</head>
<body>
<element>
<otherElement>
<elementWithIDREF idref="X"/>
</otherElement>
</element>
</body>
</doc>
With the <elementWithIDREFas a context node, I want to use an XPath
to get to the <someElementWithIDwith the corresponding id-attribute.
If I use
//head/someElementWithID[@id=@idref]
I don't get what I want, because the idref-attribute is evaluated with
someElementWithID as the context. In XSLT, I use
//head/someElementWithID[@id=current()/@idref]
But "current()" is an XSLT function. Is there some way to do this in
"pure" XPath?
Any help will be greatly appreciated,
Thomas 4 2999
* Thomas Schmidt wrote in comp.text.xml:
>I don't get what I want, because the idref-attribute is evaluated with someElementWithID as the context. In XSLT, I use
//head/someElementWithID[@id=current()/@idref]
But "current()" is an XSLT function. Is there some way to do this in "pure" XPath?
Well, can you use the id() function, or variables, or insert the value
into the expression before you have it evaluated? Otherwise there is no
way, you could only check whether there is some such element using
//head/someElementWithID/@id = @idref
which is not what you want.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
hi,
Thomas Schmidt wrote:
>
//head/someElementWithID[@id=current()/@idref]
But "current()" is an XSLT function. Is there some way to do this in
"pure" XPath?
The XPath context consist on a node, a pair of integer (size and
position), a set of namespace bindings, a set of functions, and a set of
variables
If you dont' want to augment the set of functions, you can use a
variable instead :
//head/someElementWithID[@id=$current/@idref]
but you have to set $current before, that depends on the XPath engine
and the host language you use
--
Cordialement,
///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
----------------------------- http://reflex.gforge.inria.fr/
Have the RefleX !
If you can uniquely select the element with the "idref" attribute" then use
the following expression:
//someElementWithID[@id=$the-id-ref-elemennt-selecting-expression-here/@ideref]
for example, for the provided xml document this could be as simple as:
//someElementWithID[@id = /*/*/*/elementWithIDREF/@idref]
Cheers,
Dimitre Novatchev
"Thomas Schmidt" <Be********@googlemail.comwrote in message
news:11*********************@s80g2000cwa.googlegro ups.com...
Given this document:
<doc>
<head>
<someElementWithID id="X"/>
<someElementWithID id="Y"/>
</head>
<body>
<element>
<otherElement>
<elementWithIDREF idref="X"/>
</otherElement>
</element>
</body>
</doc>
With the <elementWithIDREFas a context node, I want to use an XPath
to get to the <someElementWithIDwith the corresponding id-attribute.
If I use
//head/someElementWithID[@id=@idref]
I don't get what I want, because the idref-attribute is evaluated with
someElementWithID as the context. In XSLT, I use
//head/someElementWithID[@id=current()/@idref]
But "current()" is an XSLT function. Is there some way to do this in
"pure" XPath?
Any help will be greatly appreciated,
Thomas
Thomas Schmidt wrote:
With the <elementWithIDREFas a context node, I want to use an XPath
to get to the <someElementWithIDwith the corresponding id-attribute.
If I use
//head/someElementWithID[@id=@idref]
I don't get what I want, because the idref-attribute is evaluated with
someElementWithID as the context. In XSLT, I use
//head/someElementWithID[@id=current()/@idref]
But "current()" is an XSLT function. Is there some way to do this in
"pure" XPath?
Any help will be greatly appreciated,
Thomas
(in xslt its usually better to use a key rather than
/head/someElementWithID[@id=current()/@idref] not that that's relevant
to the problem here)
i suspect it's not possible in xpath1 unless you bind a variable in an
external language. or as Dimitre suggested, know a path to your
referencing node.
if xpath2 is a possibility, then you could use
for $id in @idref return
//head/someElementWithID[@id=$id]
David This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: 0wl |
last post by:
Hi,
I am trying to get the value of child from
xmlstr = """<p:root xmlns:p="http://tempuri.org/string"><p:child
DataType="String">Hellpppp</p:child></p:root>"""
using...
|
by: gael.pegliasco |
last post by:
Hi,
How are you dear and nice helper :) ?
I'm trying to test xpath with this simple program :
import xml.dom.minidom
from xml.xpath.Context import Context
import xml.xpath
|
by: Vijay |
last post by:
Hi
Can anybody explain what self::* means in Xpath. I understand that
"self" means the context node itself and * means any node type. So I
thought self::* meant all the child nodes of context,...
|
by: Bart |
last post by:
Hello,
I am real new to using LIBXML and have a question about XPATH
evaluations. The question may show a real ignorance of the LIBXML
structure, don't so assume I know what I am talking about....
|
by: cerelaz |
last post by:
Hi,
I need to do some Xpath queries.
How to add (or multiply) a values returned by a const?
why this //book/price/text()*10 doesn't work?
what's wrong?
thanks
ps I need to use a great c++...
|
by: David Thielen |
last post by:
Hi;
I am sure I am missing something here but I cannot figure it out. Below I
have a program and I cannot figure out why the xpath selects that throw an
exception fail. From what I know they...
|
by: Derek Hart |
last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I
run xpath statements against the xml file to grab data from it, so I use, as
an example, //Vehicles/Vehicles/@make to get...
|
by: Tim Hallwyl |
last post by:
Hi, there!
As I understand the XPaht recommendation, the context node is a node;
not a node-list, not XPath object -- but a single node.
Now, the WS-BPEL 2.0 specification allows an XML simple...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |