Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XPATH ancestor-or-self

973905Nov 13 2012 — edited Nov 13 2012
Oracle Database 10g Enterprise Edition Release 10.2.0.5 - 64bi

I'm trying to output hierarhy from element, that I found, to root using ancestor-or-self but it doesn't work at all: just print all elements(

Well, what I have:

1) An XML file like this.

*<Root>*
*<Element1 id="UniqueId1">*
*<SubElement1 id="UniqueId2"/>*
*<SubElement2 id="UniqueId3">*
*<LeafElement1 id="UniqueId4"/>*
*<LeafElement1 id="UniqueId5"/>*
*</SubElement2>*
*</Element1>*
*<Element2 id="UniqueId6" AttributeToCheck="true">*
*<SubElement1 id="UniqueId7">*
*<LeafElement1 id="UniqueId8"/>*
*<LeafElement1 id="UniqueId9"/>*
*</SubElement1>*
*</Element2>*
*</Root>*

2) My XPATH string:
//*[@id and contains(@id, "UniqueId8")]/ancestor-or-self::*

3) I want to get the result like this (from found element to root):
*<Root>*
*<Element2 id="UniqueId6" AttributeToCheck="true">*
*<SubElement1 id="UniqueId7">*
*<LeafElement1 id="UniqueId8"/>*
*</SubElement1>*
*</Element2>*
*</Root>*
By the way, //[@id and contains(@id, "UniqueId8")]/ancestor-or-self::/@id works fine.

Does anybody know how to fix this problem or just use another operation instead of ancestor-or-self?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2012
Added on Nov 13 2012
4 comments
1,085 views