문제

내가 사용하여 다음과 같은 모든 <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>s 은 실제로 정전은 한 번 설정하고,그 <xsl:param> 만 적용됩니다 호출하면 템플릿을 합니다.

이 패키지에 내가할 수 있는 적 섹션의 장호:

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

그러나 나는 그것을 할 수 있다고 생각합으로 순수 XPath.

어떤 아이디어가?감사합니다!

도움이 되었습니까?

해결책

귀하의 요구 사항을 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