[xsl] RE: Selecting the first node set

Subject: [xsl] RE: Selecting the first node set
From: "Fraser Goffin" <goffinf@xxxxxxxxxxx>
Date: Sun, 06 Aug 2006 19:46:43 +0100
Thanks to all respondants, especially Ken for explaining how predicates bind to parts of the expression (neat) ... for those that missed it :-


So, I suggest that the following will get you the first <Value> in the document regardless of the depth of the element:

(//Value)[1]

Hugh explained why your prior attempts don't work
... my wording for this is as follows: //Value[1]
won't work because the predicate is bound at the
step level so "//" looks through the entire
document and "Value[1]" which is an abbreviation
for "child::Value[1]" returns the first child
named "Value", so the combination returns "the
first child named Value at every level of the document".

This is a trick question I have had in my
hands-on XSLT training class since 1999

I just knew I should have booked your course :-)


I've also see it at conferences where vendors post it
on a white board as a "challenge" to stylesheet
writers to determine who knows their XPath and who doesn't.

Oh dear, looks like I failed that test then :-)


Fraser.

Current Thread