0

for-eachの内容をdivにラップする方法を理解するのに問題があります。各divにはそれぞれ4つの要素が含まれています。

以下に、私のXSLTの非常に簡略化されたバージョンを示します。

  <xsl:template match="/">
        <div class="container"><!-- have to be repeated for every 4 elements from the for-each -->
          <xsl:for-each select="$currentPage/GalleriListe/descendant::* [@isDoc] [not(self::GalleriListe)]">
              <div>...</div>
          </xsl:for-each>
        </div>
  </xsl:template>

何か案は?ありがとう!

4

1 に答える 1

1

XMLを投稿しなかったので、この回答には簡略化されたXMLを使用しました。それは少しハッキーです、そしてもっとエレガントな方法があるかもしれません。このXMLPlaygroundセッションでテストできます

<!-- declare how many items per container -->
<xsl:variable name='num_per_div' select='4' />

<!-- root - kick things off -->
<xsl:template match="/">
    <xsl:apply-templates select='root/node' mode='container' />
</xsl:template>

<!-- iteration content - containers -->
<xsl:template match='node' mode='container'>
    <xsl:if test='position() = 1 or not((position()-1) mod $num_per_div)'>
        <div>
            <xsl:variable name='pos' select='position()' />
            <xsl:apply-templates select='. | following-sibling::*[count(preceding-sibling::node) &lt; $pos+(number($num_per_div)-1)]' />
        </div>
    </xsl:if>
</xsl:template>

<!-- iteration content - individual items -->
<xsl:template match='node'>
    <p><xsl:value-of select='.' /></p>
</xsl:template>
于 2012-06-27T20:38:23.423 に答える