Monday, 9 September 2013

XSL - How to group a specific number of elements

XSL - How to group a specific number of elements

I have got several paragraphs and I want to display only 5 of them on a
single page. To do that I am using the keep-together="always" attribute.
for the following input:
<paragraphs>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
</paragraphs>
I would like to get something like that:
<fo:block keep-together="always">
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
</fo:block>
<fo:block keep-together="always">
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
<paragraph/>
</fo:block>
I first tried something like the following:
<xsl:template match="paragraphs">
<fo:block keep-together="always">
<xsl:for-each select="paragraph">
<xsl:if test="position() mod(5) = 1 and not(position() = 1)">
</fo:block>
<fo:block keep-together="always">
</xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
</fo:block>
</xsl:template>
but the problem is it does not compile as the closing of fo:block is
inside a xsl:if (sax parser exception when compiling).
Does anyone have an idea of how I can solve this problem?

No comments:

Post a Comment