Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] How to access the root node from within a subtemplate/recursion?

From: David Carlisle <davidc@--------->
To:
Date: 12/1/2004 12:45:00 AM
> 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
________________________________________________________________________


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent