私はchapters
というXML文書を持ち、sections
をネストしています。 私は、どのセクションでも、最初の第2レベルの祖先を見つけることを試みています。 これはancestor-or-self
軸の最後から2番目のセクションです。 擬似コード:xpathを持つ最後から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" />
まで動作し、最後の() - 1が定義されていない(現在のノードがfirst
部です)。
現在のノードがsecond
セクションの下にある場合、タイトルはsecond
です。 それ以外の場合は、タイトルがfirst
になります。
DocBookを使用するためのUpvote。 –