code_junkie

XSLT dividing a list of nodes in half

Nov 10th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <xsl:for-each select="./node [position() <= (count(*) div 2)]">
  2. <li>foo</li>
  3. </xsl:for-each>
  4. <xsl:for-each select="./node [count(*) div 2 < position()]">
  5. <li>bar</li>
  6. </xsl:for-each>
  7.  
  8. <xsl:variable name="nodes" select="node"/>
  9. <xsl:variable name="mid" select="count($nodes) div 2"/>
  10. <xsl:for-each select="$nodes[position() <= $mid]">
  11. <li>foo</li>
  12. </xsl:for-each>
  13. <xsl:for-each select="$nodes[$mid < position()]">
  14. <li>bar</li>
  15. </xsl:for-each>
  16.  
  17. <xsl:for-each select="./node [position() <= last() div 2]">
  18. <li>foo</li>
  19. </xsl:for-each>
  20. <xsl:for-each select="./node [last() div 2 < position()]">
  21. <li>bar</li>
  22. </xsl:for-each>
  23.  
  24. <xsl:for-each select="node[position() <= (count(../node) div 2)]">
  25. ...
  26. </xsl:for-each>
  27. <xsl:for-each select="node[(count(../node) div 2) < position()]">
  28. ...
  29. </xsl:for-each>
Add Comment
Please, Sign In to add comment