Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my take at it:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:variable name="split" select="3" /&gt; &lt;xsl:template match="table"&gt; &lt;xsl:variable name="self" select="." /&gt; &lt;!-- select &lt;td&gt;1&lt;/td&gt;, &lt;td&gt;4&lt;/td&gt; --&gt; &lt;xsl:for-each select="tr[1]/td[position() mod $split = 1]"&gt; &lt;xsl:apply-templates select="$self" mode="split"&gt; &lt;!-- calculate &amp; pass the starting position for copying &lt;td&gt;s --&gt; &lt;xsl:with-param name="start" select="$split * (position() - 1)" /&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;!-- this just copies the table an passes on $start --&gt; &lt;xsl:template match="table" mode="split"&gt; &lt;xsl:param name="start" select="0" /&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="tr" mode="split"&gt; &lt;xsl:with-param name="start" select="$start" /&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;!-- this copies &lt;tr&gt;/&lt;td&gt; based on $start --&gt; &lt;xsl:template match="tr" mode="split"&gt; &lt;xsl:param name="start" select="0" /&gt; &lt;xsl:copy&gt; &lt;xsl:copy-of select="td[ position() &amp;gt; $start and position() &amp;lt;= $start + $split ]" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Result:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;A&lt;/td&gt;&lt;td&gt;B&lt;/td&gt;&lt;td&gt;C&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;4&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;6&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;D&lt;/td&gt;&lt;td&gt;E&lt;/td&gt;&lt;td&gt;F&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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