[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
> 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 ________________________________________________________________________
|
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
|