Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In XSLT 1.0, using a general n-per-row template.</p> <p>With the row element name as a parameter, the n-per-row template is not tied to you input or output format.</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes" /&gt; &lt;xsl:template match="recordset"&gt; &lt;table&gt; &lt;xsl:call-template name="n-per-row"&gt; &lt;xsl:with-param name="select" select="record" /&gt; &lt;xsl:with-param name="row-size" select="2"/&gt; &lt;xsl:with-param name="row-element" select="'tr'"/&gt; &lt;/xsl:call-template&gt; &lt;/table&gt; &lt;/xsl:template&gt; &lt;xsl:template match="record"&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xsl:template&gt; &lt;xsl:template name="n-per-row"&gt; &lt;xsl:param name="select" /&gt; &lt;xsl:param name="row-size" /&gt; &lt;xsl:param name="row-element" /&gt; &lt;xsl:param name="start"&gt; &lt;xsl:text&gt;1&lt;/xsl:text&gt; &lt;/xsl:param&gt; &lt;xsl:variable name="count" select="count($select)" /&gt; &lt;xsl:variable name="last-tmp" select="number($start) + number($row-size)" /&gt; &lt;xsl:variable name="last"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$last-tmp &amp;gt; $count"&gt; &lt;xsl:value-of select="$count"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="$last-tmp"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; &lt;xsl:element name="{$row-element}"&gt; &lt;xsl:apply-templates select="$select[position() &amp;lt;= $last]"/&gt; &lt;/xsl:element&gt; &lt;xsl:if test="count($select) &amp;gt; $last"&gt; &lt;xsl:call-template name="n-per-row"&gt; &lt;xsl:with-param name="select" select="$select[position() &amp;gt; $last]"/&gt; &lt;xsl:with-param name="row-size" select="$row-size"/&gt; &lt;xsl:with-param name="row-element" select="$row-element"/&gt; &lt;xsl:with-param name="start" select="$start"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload