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 October 8th, 2008, 12:27 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default searching children of ancestors

This may take a minute to explain, so please be patient.

I am using Saxon 9 on Windows.

I have a source document a simple structure such as:

a - b - x - y
      + c - d - e
      + c - d - e
      + c - d - e
  + b - x - y
      + c - d - e
      + c - d - e
      + c - d - e
  + b - x - y
      + c - d - e
      + c - d - e
      + c - d - e

My structure is really much deeper, but this will do to explain my problem.

I find myself at a 'y' node and I decide I need information from all the 'e' nodes that are descendants of my current 'b' node. I don't care about the 'e' nodes that are descendants of the other 'b' nodes.

My initial thought was to use: ancestor::node()//e to get the information. Problem is, and it is now obvious to me, I am getting all the 'e' nodes in the document, not just the ones that are descendants of my 'b' node.

What I need is a way to stop the ancestor once it has a hit on a descendant 'e' node, then reuse that ancestor to find all the 'e' nodes I am interested in.

Or I need another solution.




------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old October 8th, 2008, 12:55 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

There are many different ways of doing this depending out how fixed your structure is. But simply doing this should work:

ancestor::b//e

obviously if you know what b is two levels up from y, and e is two levels down, then something like the following would be much faster:

../../b/c/d/e

or perhaps if you don't know what c and d will be then the following:

../../b/*/*/e

/- Sam Judson : Wrox Technical Editor -/
 
Old October 8th, 2008, 01:09 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Yes, that is a possibility. What I had tried was to be more generic than needing to know the depth of the 'y' and the static relative position from it to the 'e' nodes.

Now, ancestor::b//e seems interesting. Maybe I was not using the ancestor construct correctly.
I will try that and see if it works.

Thanks!



------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
help with nodes/children bmmayer XML 0 July 13th, 2007 05:04 PM
MDI Children angelboy C# 2005 5 June 28th, 2007 06:08 AM
match only first level children sgruhier XSLT 1 February 22nd, 2005 05:12 AM
get all children nodes maratg XSLT 4 November 7th, 2003 02:07 PM
Trying to get node name of childs children keldan XML 1 August 1st, 2003 03:11 PM





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