Altova Mailing List Archives

Re: [XSL] Obtaining an attribute from self or ancestor

From: "Dimitre Novatchev" <dnovatchev@-----.--->
Date: 10/25/2008 1:51:00 PM
"Richard Tobin" <richard@c...> wrote in message 
> In article <490139f9$0$17067$6e1ede2f@r...>,
> Dimitre Novatchev <dnovatchev@c...> wrote:
>>Actually, this can be achieved with a single XPath one-liner (even without
>>XSLT being involved).
>>   //node[@id = $id]/ancestor-or-self::*[@attr][1]/@attr
> Or, if you find it clearer not to repeat @attr:
>   (//node[@id = $id]/ancestor-or-self::*/@attr)[last()]

This may be "clearer" but risks to be less efficient.

Using [1] in a reverse axis is a strong optimization hint and a clever XPath 
engine will not traverse the whole way up -- it wil just stop on the first 
self-or-ancestor element found that has an "attr" attribute.

Dimitre Novatchev 


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.