Need to find parent node position from child
<w:tbl>
<w:tr&g开发者_Python百科t; </w:tr>
<w:tr> </w:tr>
<w:tr>
<w:tc>
<p>i am here</p>
<w:tc>
</w:tr>
</w:tbl>
I am using xslt 1.0.
It's a xml sample code for table(w:tbl-->table,w:tr-->row,w:tc-->td)
. Now I am in w:tc template match. I want to know the position of parent node ie. w:tr (which is 3). How can i get it from the tc template itself?
Note I have put <xsl:apply-templates>
in w:tc template match.
<xsl:value-of select="count(../preceding-sibling::*)+1"/>
If you want to consider parent position only relative to the elements like it:
<xsl:value-of select="count(../preceding-sibling::w:tr)+1"/>
I am in need to get the cell position number from template. The following line might help some one
count(ancestor::w:tc/preceding-sibling::w:tc)
How about:
<xsl:value-of select="count(parent::*/preceding-sibling::w:tr)"/>
It counts the preceding siblings of the parent node with respect to w:tr
elements, which should be the same as the parents position in that table.
精彩评论