xpathを使用して完全なドキュメント内の親ノードの位置を取得するには?
次の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>
そして、それを HTML に変換するための XSLT があります。これは次のとおりです (スニペットのみ)。
<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>
????の所には何を書けばいいですか?ドキュメント内の親 cd タグの位置を取得します。多くの表現を試しましたが、何も機能していないようです。私はそれを完全に間違っているかもしれません。
<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/>
現在のノードの親軸を選択し、現在のノードの親の位置を伝えるように2番目を解釈しています。なぜ機能しないのですか?これを行う正しい方法は何ですか。
参考までに: 現在のタイトル タグ uder 処理の親 cd タグの位置を出力するコードを期待しています。
誰かがこれを行う方法を教えてください。