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

Count of previous nodes until a child node of a previo

Subject: Count of previous nodes until a child node of a previous node is found with certain attribute value
From: "Jeremy Freedman" <jeremy.freedman@xxxxxxxxx>
Date: Sat, 26 May 2007 15:21:33 -0400
 Count of previous nodes until a child node of a previo
Hi all,

I'm the first to admit I'm not XSL expert, but I've been stuck on this
one for hours and I'm hoping someone can help me out.

I've found similar posts where a user is looking for a count of
following nodes until an attribute is found, but not close enough to
what I'm looking to do.

Assuming we have this XML structure:

<body>
   <p>
         text
   </p>
  <p>
         text2
   </p>
   <p>
         <component name="newpage" />
   </p>
   <p>
         text3
   </p>
  <p>
         text4
   </p>
   <p>
         text5
   </p>
  <p>
         text6
   </p>
   <p>
         <component name="newpage" />
   </p>
   <p>
         text7
   </p>
  <p>
         text8
   </p>
   <p>
         text9
   </p>
</body>


I want to be able to find the count of preceding "p" nodes from the p node I am on, up until I find a "p" node with a child node named "component" with attribute name=newpage.

Examples:

If I am on the p node whose value is "text8", I should get a count of
1 because there is only 1 previous p node before I find a p node with
the component node with attribute name=newpage.

p node value            Count
text                          0
text2                        1
text3                        0
text4                        1
text5                        2
text6                        3
text7                        0
text8                        1
text9                        2


You will be my personal hero is you can help me out!


Much thanks,

Jeremy

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.