xsl-list
[Top] [All Lists]

Re: Sample Code for multiple fo:page-sequence

2002-12-19 14:09:03
At 2002-12-19 15:52 -0500, Prateek Gupta wrote:
- call for a page sequence per new page, wherein I specify that the number
of records per page is, say, 5
Can anyone point out how I can re-code my XSL.

This is another example of going from no structure (a single collection of rows) into structure (multiple collections of nodes).

An example is below.

I hope this helps.

................ Ken


T:\ftemp>type prateek.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<table>
  <row>Row 1</row>
  <row>Row 2</row>
  <row>Row 3</row>
  <row>Row 4</row>
  <row>Row 5</row>
  <row>Row 6</row>
  <row>Row 7</row>
  <row>Row 8</row>
  <row>Row 9</row>
  <row>Row 10</row>
  <row>Row 11</row>
  <row>Row 12</row>
  <row>Row 13</row>
  <row>Row 14</row>
  <row>Row 15</row>
  <row>Row 16</row>
  <row>Row 17</row>
  <row>Row 18</row>
  <row>Row 19</row>
  <row>Row 20</row>
  <row>Row 21</row>
  <row>Row 22</row>
  <row>Row 23</row>
  <row>Row 24</row>
  <row>Row 25</row>
  <row>Row 26</row>
  <row>Row 27</row>
</table>
T:\ftemp>type prateek.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:output indent="yes"/>

<xsl:template match="table">
  <result>
    <xsl:for-each select="row[ position() mod 5 = 1 ]">
      <page-sequence>
        <table>
          <xsl:copy-of select="."/>
          <xsl:for-each select="following-sibling::row[ position() &lt; 5 ]">
            <xsl:copy-of select="."/>
          </xsl:for-each>
        </table>
      </page-sequence>
    </xsl:for-each>
  </result>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt prateek.xml prateek.xsl
<?xml version="1.0" encoding="utf-8"?>
<result>
<page-sequence>
<table>
<row>Row 1</row>
<row>Row 2</row>
<row>Row 3</row>
<row>Row 4</row>
<row>Row 5</row>
</table>
</page-sequence>
<page-sequence>
<table>
<row>Row 6</row>
<row>Row 7</row>
<row>Row 8</row>
<row>Row 9</row>
<row>Row 10</row>
</table>
</page-sequence>
<page-sequence>
<table>
<row>Row 11</row>
<row>Row 12</row>
<row>Row 13</row>
<row>Row 14</row>
<row>Row 15</row>
</table>
</page-sequence>
<page-sequence>
<table>
<row>Row 16</row>
<row>Row 17</row>
<row>Row 18</row>
<row>Row 19</row>
<row>Row 20</row>
</table>
</page-sequence>
<page-sequence>
<table>
<row>Row 21</row>
<row>Row 22</row>
<row>Row 23</row>
<row>Row 24</row>
<row>Row 25</row>
</table>
</page-sequence>
<page-sequence>
<table>
<row>Row 26</row>
<row>Row 27</row>
</table>
</page-sequence>
</result>


--
Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO:
-                             North America:  Feb 3 - Feb 7,2003

G. Ken Holman               mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.        http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                     Definitive XSLT and XPath
ISBN 0-13-140374-5                             Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1             Practical Formatting Using XSL-FO
Next conference training:                          2003-03-03,06


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>