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

Re: How to access the root node from within a subtemp

Subject: Re: How to access the root node from within a subtemplate/recursion?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 1 Dec 2004 00:44:24 GMT
subtemp
> Obviously xslt only knows the local tree at the current recursion level.
> Is there a way to access the root node of the whole outer tree?

XSLT has full access to teh entire tree (trees in fact) at all times.

> <xsl:template match="//myelem[@name = 'peter']">
you don't want the // there it isn't doing anything useful the
stylesheet would work the same way with
<xsl:template match="myelem[@name = 'peter']">

     <!-- now I want to jump to the node <myelem name="karl"> with the subnode 'tony'
          but this doesn't work because this node is outside the context/scope -->
     <xsl:with-param name="nametofind" select="//myelem[@name =
          $nametofind]" />

//myelem  will search the whole document for an element of that name, so
unless you have multiple documents (from document() or xx:node-set()
functions) this wil find the element.

If you do have multiple documeents and want to get back to your original
one, put
<xsl:variable name="originaldoc" select="/"/>
at teh top level of your stylesheet (outside any template)
then you can go
     <xsl:with-param name="nametofind" select="$originaldoc//myelem[@name = $nametofind]" />

Note that // can be very expensive/slow and you probably would get great
efficiency gains by using keys. (butget it working before getting it
optimised)

> How do I access from a given subtree the outer whole tree resp. other
> nodes?
if it really is a subtree then just using / will work, if it's a
different tree, use a variable holding the original root node, as
above. 

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.