Re: [xsl] Getting variable yet most immediate parentNode

Subject: Re: [xsl] Getting variable yet most immediate parentNode
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 27 Sep 2007 18:54:07 -0400

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):

I ususally advise against it, but this is a good place to code:

<xsl:apply-templates select=".//answers" />

Actually this should be "ancestor::*/answers", or "ancestor::*[answers][1]/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][1]/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.)


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread