Re: Getting variable yet most immediate parentNode
At 04:40 PM 9/27/2007, was written:
In addition, you have three ways of writing 'answers': ,../answers, ../../answers and ../../../answers. I am sure that while you were writing it you were thinking something like "it must be possible to achieve this effect more easily"... There are several ways to code around the path-depth problem, but the easiest is probably to leave the path out completely, if you are certain that "answer" elements are what they are at any level: answer elements (and even if you do find later that you have different treatment for different answer-elements, you will simply add a new rule):
Actually this should be "ancestor::*/answers", or "ancestor::*[answers]/answers", shouldn't it?
".//answers" will search the subtree below the current node, rather than look up the tree.
"ancestor::*/answers" will select answers elements from all ancestors; "ancestor::*[answers]/answers" will select only the closest one. If you think the latter expression is too opaque, you could also write
... and then try to explain that. :-)
(Steve, the rest of what Abel says is true: you can refactor your code into apply-templates select="[the appropriate expression above]" and lose all those "when" clauses without fear.)
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