[Home] [By Thread] [By Date] [Recent Entries]
At 2006-08-05 12:21 +0100, Fraser Goffin wrote:
Given the following simplified XML instance, can anyone suggest an expression that will return ONLY the 'Value' node containing <enum> children with values A, B and C. I can't rely on the name of the parent node of <Value> hence I have deliberately named these as UnknownNameX or any other intervening structure.
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 when it was still combined with DSSSL training. 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. I hope this helps, Fraser, . . . . . . . . . . . . . . Ken -- UBL/XML/XSLT/XSL-FO training: Verx, Denmark 06-09-25/10-06 World-wide corporate, govt. & user group UBL, XSL, & XML training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|

Cart



