質問

すべてを一致させるために次を使用しています <section>s にはリビジョン属性が設定されています。 <section>ドキュメント ツリーのさまざまなレベルに表示され、常に以下に含まれます。 <chapter>s.

<xsl:for-each select="//section[@revision]">
    <!-- Do one thing if this is the first section 
           matched in this chapter -->

    <!-- Do something else if this section is in the same 
           chapter as the last section matched -->
</xsl:for-each>

コメントにあるように、それぞれを作成する必要があります for-each 反復は、その章が属する章を認識します。 前の 一致したセクションが属していました。私はそれを知っています <xsl:variable>は実際には一度設定されると静的になります。 <xsl:param> テンプレートの呼び出しにのみ適用されます。

これは Docbook なので、次のようにしてセクションの章番号を取得できます。

<xsl:apply-templates select="ancestor::chapter[1]" mode="label.markup" />

しかし、純粋にXPathで実行できると思います。

何か案は?ありがとう!

役に立ちましたか?

解決

私はあなたの要件unterstood 100%、しかし場合は、

わからない...

<xsl:variable name="sections" select="//section[@revision]" />

<xsl:for-each select="$sections">
  <xsl:variable name="ThisPos" select="position()" />
  <xsl:variable name="PrevMatchedSection" select="$sections[$ThisPos - 1]" />
  <xsl:choose>
    <xsl:when test="
      not($PrevMatchedSection)
      or
      generate-id($PrevMatchedSection/ancestor::chapter[1])
      !=
      generate-id(ancestor::chapter[1])
    ">
      <!-- Do one thing if this is the first section 
           matched in this chapter -->
    </xsl:when>
    <xsl:otherwise>
      <!-- Do something else if this section is in the same 
           chapter as the last section matched -->
    </xsl:otherwise>
  </xsl:choose>  
</xsl:for-each>

しかし、私は、この全体のことは<xsl:template> / <xsl:apply-templates>のアプローチで、よりエレガントに解決することができると思います。しかし、あなたの入力と期待される出力を見ることなく、これは言い難います。

他のヒント

位置は()現在のために、各反復の中に自分の位置を返します。あなたが最初の反復である場合は、最初の反復、IIRCは、そのためのテスト、0を返します「)の位置(= 0」を教えてくれます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top