[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: XPath to select based on attr = same attr of an a
> KH> foreign[@lang = ancestor::*[@lang][1]/@lang] > > MK> foreign[@lang = (ancestor::*/@lang)[last()]] These are equivalent. (1) take the lang attribute of the first ancestor element (going upwards) that has a lang attribute (2) take all the lang attributes belonging to ancestor elements, then select the last (going downwards). > I would, however, like to understand why > foreign[@lang][ancestor::*[@lang]][1][ ./@lang = > ./ancestor::*[@lang][1]/@lang ] doesn't work. I've forgotten the details of the question, but I think the culprit is the first [1]. The predicates [@lang] and [ancestor::*[@lang]] are harmless - if the final predicate is true, then these predicates will also be true. But the [1] means you only select the first <foreign> element for which these predicates apply, which is not the case for the KH and MK expressions above. > > And am I right that the difference between the KH and MK > construc- tions are that the former is looking up the > ancestor axis for the first hit, whereas the latter is > looking down the ancestor axis for the last hit? Is one > "better" than the other in any significant way? > Probably the KH construction gives a better chance that the system will stop its search of the ancestor axis early. On the other hand, it seems inelegant having to access the @lang attribute of each ancestor twice. Michael Kay http://www.saxonica.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|