Find position of parent node using xpath

CyberRooT

New Member
How to get the position of parent node in the complete document using xpath?say I have the following xml:\[code\]<catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd></catalog>\[/code\]and I have a XSLT to convert it into HTML, which is as follows (only snippet):\[code\]<xsl:template match="/"><html> <body> <xsl:apply-templates/> </body> </html></xsl:template><xsl:template match="cd"> <p> <xsl:number format="1. "/><br/> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </p></xsl:template><xsl:template match="title"> <xsl:number format="1" select="????" /><br/> Title: <span style="color:#ff0000"> <xsl:value-of select="."/></span> <br /></xsl:template>\[/code\]What should I write at the place of ???? to get position of the parent cd tag in the document.I have tried many expressions but nothing seems to be working. May be I am doing it altogether wrong.[*]\[code\]<xsl:number format="1" select="catalog/cd/preceding-sibling::..[position()]" />\[/code\][*]\[code\]<xsl:number format="1" select="./parent::..[position()]" /><br/>\[/code\][*]\[code\]<xsl:value-of select="count(cd/preceding-sibling::*)+1" /><br/>\[/code\]I am interpreting 2nd as select current node's parent axis and then tell the position of parent of the current node. Why is it not working? What is the correct way to do this.FYI: I expect the code to print the position of parent cd tag of the current title tag uder processing.Please can someone tell me how to do this.
 
Back
Top