이 등 핸들 위치 1, 3, 5,에 요소에 대한 실행이
<xsl:for-each select="$datapath/PackageInfoList/PackageInfo[position() mod 2 = 1]">
<div>
<!-- lots of html in here -->
<!-- do something with following-sibling::PackageInfo[1] -->
</div>
</xsl:for-each>
처럼 홀수 <PackageInfo>
요소를 선택 각각 수동으로 <PackageInfo>
을 따르십시오.
더 관용적
<xsl:template match="/">
<xsl:apply-templates select="$datapath/PackageInfoList/PackageInfo" mode="group2" />
</xsl:template>
<xsl:template match="PackageInfo" mode="group2">
<xsl:if test="position() mod 2 = 1">
<div>
<xsl:apply-templates select=". | following-sibling::PackageInfo[1]" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="PackageInfo">
<!-- lots of html in here -->
</xsl:template>
유연
<xsl:template match="/">
<xsl:apply-templates select="$datapath/PackageInfoList/PackageInfo" mode="group">
<xsl:with-param name="groupcount" select="2" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="PackageInfo" mode="group">
<xsl:param name="groupcount" select="2" />
<xsl:if test="position() mod $groupcount = 1">
<div>
<xsl:apply-templates select=". | following-sibling::PackageInfo[position() < $groupcount]" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="PackageInfo">
<!-- lots of html in here -->
</xsl:template>
검사 할 수있다 [이 응답 (http://stackoverflow.com/a/9908661/2633606). – rcgoncalves