Re: [xsl] Divide to pages

Subject: Re: [xsl] Divide to pages
From: Paull <paullus4mlist@xxxxxxxxx>
Date: Wed, 05 Apr 2006 18:53:59 +0300
andrew welch wrote:

On 4/5/06, Paull <paullus4mlist@xxxxxxxxx> wrote:


Hello All,
following xml:
<data>
<item name="1" id="i1">v1</item>
<item name="2" id="i1">v2</item>
<item name="3" id="i1">v1</item>
<item name="4" id="i1">v1</item>
<item name="5" id="i1">v2</item>
<item name="6" id="i1">v1</item>
<item name="7" id="i1">v1</item>
<item name="8" id="i1">v2</item>
<item name="9" id="i1">v1</item>

<item name="10" id="i2">v2</item>
<item name="11" id="i2">v2</item>
<item name="12" id="i2">v2</item>


<group name="g1" id="i1"/> <group name="g2" id="i2"/> </data> should be transformed to the xml, where items are grouped by id, and divided to pages whith 5 items per page. Result should be like following: g1 1. i1v1 2. i1v2 3. i1v1 4. i1v1 5. i1v2 EOP 1. i1v1 2. i1v1 3. i1v2 4. i1v1 g2 5. i2v2 EOP 1. i2v2 2. i2v2

I can group it, but how to divide for pages - no idea ...



It's difficult to give an exact answer without seeing how you are grouping, but this can be achieved using mod, eg position() mod 5 = 0 will give you every fifth item.



I'm grouping with following:

<xsl:template match="/data">
<xsl:for-each select="group">
<xsl:variable name="id" select="@id"/>
<b><xsl:value-of select="$id"/></b><br/>
<xsl:apply-templates select="/data/item[@id=$id]" />
</xsl:for-each> </xsl:template>


<xsl:template match="item">
  <xsl:value-of select="@id"/> <xsl:value-of select="."/><br/>
<xsl:if test="position() mod 5 = 0">
   <!-- EOP -->
</xsl:if>
</xsl:template>

But using <xsl:if test="position() mod 5 = 0"> is not correct because it not handles situation with 5 groups each with one item should be pasted into one page.

Current Thread