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

Subject: RE: [xsl] Counting level of nodes beneath current (in XPATH)
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Tue, 11 Jan 2005 12:37:30 +0000
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