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

RE: Counting level of nodes beneath current (in XPATH)

Subject: RE: Counting level of nodes beneath current (in XPATH)
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Tue, 11 Jan 2005 12:37:30 +0000
one.lv
Hi again,

I will try if this example explains it better...

With the example XML:

<X>
 <Y>
   <Z>lv 1 (one lv. descendants)</Z>
   <X>
     <Y>
       <Z>lv 2 (zero lv. descendants)</</Z>
     </Y>
   </X>
 </Y>
 <Y>
   <Z>lv 1 (two lv. descendants)</</Z>
   <X>
     <Y>
       <Z>lv 2 (one lv. descendants)</</Z>
       <X>
         <Y>
           <Z>lv 3 (zero lv. descendants)</Z>
         </Y>
       </X>
     </Y>
     <Y>
       <Z>lv 2 (two lv. descendant)</Z>
       <X>
         <Y>
           <Z>lv 3 (zero lv. descendant)</Z>
         </Y>
       </X>
       <X>
         <Y>
           <Z>lv 3 (one lv. descendants)</Z>
           <X>
             <Y>
               <Z>lv 4 (zero lv. descendants)</Z>
             </Y>
             <Y>
               <Z>lv 4 (zero lv. descendants)</Z>
             </Y>
           </X>
         </Y>
       </X>
     </Y>
   </X>
 </Y>
</X>

With a parameter $lv="2", and an id-transformation, I should get the xml without (zero lv. descendants) and (one lv. descendants), that is:

<X>
 <Y>
   <Z>lv 1 (two lv. descendants)</</Z>
   <X>
      <Y>
       <Z>lv 2 (two lv. descendant)</Z>
    </X>
 </Y>
</X>

With $lv="1" I should get all except (zero lv. descendatnts), that is, without leaf Y-nodes (and without the X-node containing the leaf Y-nodes):

<X>
 <Y>
   <Z>lv 1 (one lv. descendants)</Z>
 </Y>
 <Y>
   <Z>lv 1 (two lv. descendants)</</Z>
   <X>
     <Y>
       <Z>lv 2 (one lv. descendants)</</Z>
     </Y>
     <Y>
       <Z>lv 2 (two lv. descendant)</Z>
       <X>
         <Y>
           <Z>lv 3 (one lv. descendants)</Z>
         </Y>
       </X>
     </Y>
   </X>
 </Y>
</X>

So in all, instead of wanting, say the first two levels of Y-nodes, instead I want all the nodes top-down, except for ie. buttom 2 levels.

I would be happy if I, from a given node, could count how many levels of Y-nodes where below the current. I do not know if that was the answer that David Carlisle gave, I did not understand the answer that well (which is fair enough given that my question was perhaps not understood :-) )

I hope that with this, my question is clear, and that an XPath solution is possible.

Regards,
Ragulf Pickaxe :-)

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


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.