chapters
がネストされたXMLドキュメントがありますsections
。私は、どのセクションでも、最初の第2レベルのセクションの祖先を見つけようとしています。ancestor-or-self
これは、軸の最後から2番目のセクションです。擬似コード:
<chapter><title>mychapter</title>
<section><title>first</title>
<section><title>second</title>
<more/><stuff/>
</section>
</section>
</chapter>
私のセレクター:
<xsl:apply-templates
select="ancestor-or-self::section[last()-1]" mode="title.markup" />
もちろん、これはlast()-1が定義されていないまで機能します(現在のノードはfirst
セクションです)。
現在のノードがsecond
セクションの下にある場合は、タイトルが必要ですsecond
。それ以外の場合は、タイトルが必要ですfirst
。