Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
Hi All,

I want to count the total number of specific nodes between root node and current node. for Example:

<pre lang="text"><w:body xmlns:w="#unknown"> <!-- root Node -->
     <w:p />
             <w:rect>
             <w:p>some text1</w:p>  
            </w:rect>
     <w:p />
             <w:rect>
              <w:p>some text2</w:p>  
            </w:rect>

     <w:p />
     <w:p />
     <w:p />
            <w:rect>
             <w:p>some text5</w:p>   <!-- This is current node now -->
            </w:rect>
     <w:p />
     <w:p />
     <w:p />
     <w:p />
</w:body>



This is my scenario.Here, Assume some text is my current node.So, Now i want to get the parent::w:p of the current node (Assume this node name as "targetNode"). After that i want to calculate total number of the same level of w:p from root node to targetNode.

My wanted output is :5

Please Guide me to get out of this issue...
Posted

1 solution

count(ancestor::w:p[1]/preceding-sibling::w:p + 1)(the first ancestor w:p itself).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900