XPATH ancestor-or-self
973905Nov 13 2012 — edited Nov 13 2012Oracle 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?