Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2009, 11:52 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default Can you apply templates backwards?

if I have this structure

Code:
<A>
    <B></B>
    <B>
        <C>
            <D></D>
            <E>
                <F></F>
            </E>
        </C>
    </B>
    <B></B>
</A>
Can i get this structure
Code:
<A>
    
    <B>
        <C>
            
            <E>
                <F></F>
            </E>
        </C>
    </B>
    
</A>
when given the element F as the starting point? That is get a direct path back to the root? The names of the elements are different every time, we just get given the starting location.

Last edited by JohnBampton; March 5th, 2009 at 11:54 AM..
 
Old March 5th, 2009, 12:59 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you can bind a global variable $F to the F node, then you can do (in XSLT 2.0)

Code:
<xsl:variable name="F" select="..."/>

<xsl:variable name="ancestors" select="$F/ancestor-or-self::*"/>

<xsl:template match="*[. intersect $ancestors]">
  <xsl:copy>
    <xsl:apply-templates/>
  </
</

<xsl:template match="*"/>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following 2 Users Say Thank You to mhkay For This Useful Post:
JohnBampton (March 5th, 2009), tsmets (July 12th, 2010)
 
Old March 5th, 2009, 01:26 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

With a bit of modification to include attributes it worked really well, thanks a lot





Similar Threads
Thread Thread Starter Forum Replies Last Post
Exclude Elements in Apply Templates mail4kaja XSLT 18 November 29th, 2008 12:09 PM
Apply-templates combined with with-param ? Smirre XSLT 6 November 11th, 2008 08:25 AM
apply-templates problem within for-each loop mister_mister XSLT 2 January 22nd, 2007 05:40 PM
Templates Won't Apply neilac333 XSLT 5 October 26th, 2006 01:39 PM
using preceding-sibling in apply-templates subset rathbird XSLT 0 April 16th, 2004 10:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.