'XSL-FO Move cell to the next row when there is already a specific number of cells in the row

I need to create a table, where is 12 columns and could be many rows. Now i have something like this: enter image description here

And I would like to have something like this: SOME TEXT

However finally it won't necessary will by multiplicity of twelves in a row, it could be partial filled.

My test xml (actually I create the data structure from scratch, so if necessary, I can slightly modify it):

        <ColsNo>14</ColsNo>
        <Fines>
            <Fine>
                <No>1</No>
                <Price>100</Price>
            </Fine>
            <Fine>
                <No>2</No>
                <Price>200</Price>
            </Fine>
            <Fine>
                <No>3</No>
                <Price>300</Price>
            </Fine>
              ...
            <Fine>
                <No>14</No>
                <Price>1400</Price>
            </Fine>
       </Fines>

My xsl so far:

 <fo:table width="100%" table-layout="fixed" margin-left="2pt" margin-right="2pt">

    <fo:table-column column-width="7cm" border-style="solid" border-width="0.5px"/>
    <xsl:variable name="n" select="count(Fines/Fine)" />
    <xsl:for-each select="Fines/Fine">                                          
        <fo:table-column column-width="auto" border-style="solid" border-width="0.5px"/>
    </xsl:for-each>                                     

    <!-- generate 12 cols -->                                       
    <!--
     <xsl:variable name="nodes" select="//node() | //namespace::* | //comment() | //processing-instruction()" />
    <xsl:for-each select="$nodes[position() &lt; 13]"> 
        <fo:table-column column-width="auto" border-style="solid" border-width="0.5px"/>
    </xsl:for-each>
    -->

    <xsl:template match="Fines">
        <fo:table>
            <fo:table-body>
                <xsl:apply-templates/>
            </fo:table-body>
        </fo:table>
    </xsl:template>

    <xsl:template match="Fines/Fine">
        <xsl:variable name="pos" select="position()"/>

        <fo:table-body>
            <fo:table-row>
                <fo:table-cell number-rows-spanned="4" border-width="0.5px">
                    <fo:block>SOME TEXT
                    </fo:block>
                </fo:table-cell>

                <xsl:for-each select="Fines/Fine">
                    <xsl:if test="not($pos mod 12)">
                        <xsl:attribute name="ends-row">true</xsl:attribute>
                    </xsl:if>
                    <fo:table-cell border-style="solid" border-width="0.5px"
                                                                       background-color="white">
                        <fo:block font-weight="bold">
                            <xsl:value-of select="./No"/>
                        </fo:block>
                    </fo:table-cell>
                </xsl:for-each>
            </fo:table-row>

            <fo:table-row>
                <xsl:for-each select="Fines/Fine">
                    <xsl:if test="not($pos mod 12)">
                        <xsl:attribute name="ends-row">true</xsl:attribute>
                    </xsl:if>
                    <fo:table-cell border-style="solid" border-width="0.5px"
                                                                       background-color="white">
                        <fo:block font-weight="bold">
                            <xsl:value-of select="./Price"/>
                        </fo:block>
                    </fo:table-cell>
                </xsl:for-each>
            </fo:table-row>


            <fo:table-row>
                <xsl:if test="not($pos mod 12)">
                    <xsl:attribute name="ends-row">true</xsl:attribute>
                </xsl:if>
                <fo:table-cell border-style="solid" border-width="0.5px"
                                                                   background-color="white">
                    <fo:block font-weight="bold">
                        <xsl:value-of select="./Price"/>
                    </fo:block>
                </fo:table-cell>
            </fo:table-row>

            <xsl:variable name ="var1">
                <xsl:value-of select="ColsNo"/>
            </xsl:variable>


            <xsl:for-each select="$nodes[position() &lt; ceiling($var1 div 12)+1]">
                <fo:table-row>
                    <fo:table-cell border-style="solid" border-width="0.5px"
                                                                       background-color="white">
                        <fo:block font-weight="bold">
                            <xsl:value-of select="position()"/> 
                        </fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </xsl:for-each>


        </fo:table-body>
    </xsl:template>
</fo:table>

I figure out how to create 12 cols in loop (a bit weird but ok) but I don't know how to move this redundant cells to new row.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source