Split node list to parts.
- by Kalinin
xml:
<mode>1</mode>
<mode>2</mode>
<mode>3</mode>
<mode>4</mode>
<mode>5</mode>
<mode>6</mode>
<mode>7</mode>
<mode>8</mode>
<mode>9</mode>
<mode>10</mode>
<mode>11</mode>
<mode>12</mode>
i need to separate it on parts (for ex. on 4):
xslt:
<xsl:variable name="vNodes" select="mode"/>
<xsl:variable name="vNumParts" select="4"/>
<xsl:variable name="vNumCols" select="ceiling(count($vNodes) div $vNumParts)"/>
<xsl:for-each select="$vNodes[position() mod $vNumCols = 1]">
<xsl:variable name="vCurPos" select="(position()-1)*$vNumCols +1"/>
<ul>
<xsl:for-each select="$vNodes[position() >= $vCurPos and not(position() > $vCurPos + $vNumCols -1)]">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:for-each>
this code is written by Dimitre Novatchev - great coder))
but for the number of nodes less then number of parts (for ex. i have 2 modes) this code does not work - it outputs nothing.
How it upgrade for that case (without choose construction)?