[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Getting variable yet most immediate parentNode

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

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

(ancestor::*/answers)[last()]

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

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.