How to get the position of the parent node in a full document using xpath?
Let's say I have the following xml:
<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>
and I have XSLT to convert it to HTML, which looks like this (snippet only):
<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>
What should I write on the spot ???? to get the position of the parent cd tag in the document. I tried many expressions but nothing works. Maybe I'm doing it completely wrong.
<xsl:number format="1" select="catalog/cd/preceding-sibling::..[position()]" /><xsl:number format="1" select="./parent::..[position()]" /><br/><xsl:value-of select="count(cd/preceding-sibling::*)+1" /><br/>
I interpret the second how to select the current parent axis of the node, and then pass the position of the parent of the current node. Why is this not working? What is the right way to do this.
FYI: I expect the code to print the position of the parent cd tag of the current processing of the header header tag.
Please tell me how to do this.
Harshdeep
source share