我有多个类别,我想将其分成几行,一行中的类别数将基于$catsInLine
. 是从 1 到 12的$catsInLine
数字。每个类别将由类从 span1 到 span 12 的 DIV 包装。类别将再次包装<div class="row-fluid">
每一行。
我在下面尝试了几个小时,但没有得到正确的结果。
<div class="row-fluid">
<xsl:variable name="catsInLine">
<xsl:value-of select="categories_in_line" />
</xsl:variable>
<xsl:variable name="column">
<xsl:value-of select="(12 div $catsInLine)" />
</xsl:variable>
<xsl:for-each select="categories/category">
<xsl:if test="position() mod $catsInLine = 1 or position() = 1">
<xsl:text disable-output-escaping="yes"><div class="row-fluid"></xsl:text>
</xsl:if>
<div class="span{$column}">
<xsl:call-template name="category" />
</div>
<xsl:if test="position() mod $catsInLine = 0 or position() = last()">
<xsl:text disable-output-escaping="yes"></div></xsl:text>
</xsl:if>
</xsl:for-each>
</div>
假设$catsInLine
是2
,我希望得到的结果是
<div class="row-fluid">
<div class="span6">
<a>Category1</a>
</div>
<div class="span6">
<a>Category2</a>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<a>Category3</a>
</div>
<div class="span6">
<a>Category4</a>
</div>
</div>
如果$catsInLine
是1
,结果应该是
<div class="row-fluid">
<div class="span12">
<a>Category1</a>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<a>Category2</a>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<a>Category3</a>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<a>Category4</a>
</div>
</div>