I'm using XSLT 1.0 to transform some XML documents. I have a problem to do one thing, in that I would need some help please:
I have a set of items in my XML document something like :
<item1>...</item1>
<item2>...</item2>
<!-- ... -->
<itemN>...</itemN>
I want to create something like this based on delta (items per page), for example delta is three:
<page>
<item1>...</item1>
<item2>...</item2>
<item3>...</item3>
</page>
<page>
<item4>...</item4>
<item5>...</item5>
<item6>...</item6>
</page>
So, basically to create a XML structure in XSLT that will put fixed number of items per page.
If tried something like this (in order to use node-set):
<xsl:variable name="all_items_per_delta">
<xsl:for-each select="item">
<!-- if position is one or if mod of 3 then insert a page node,
so for first contract and for 3th, 6th, 9th... item -->
<xsl:if test="position() = 1">
<page>
</xsl:if>
<!-- in the meantime for every contract insert the contract node -->
<item>
<!-- ... -->
</item>
<!-- if position is one or if mod of 3 then insert a page node,
so for first item and for 3th, 6th, 9th... item-->
<xsl:if test="( (position() mod 3) = 0) ) and ( position() != last() )">
</page>
<page>
</xsl:if>
<!-- if the position is last just end the page element -->
<xsl:if test="position() = last()"> `
</page>
</xsl:if>
</xsl:for-each>
</xsl:variable>
But this doesn't work because the xslt parser says
'Expected end of tag 'page'
and this is for the first <page>
tag I want to add. It seems that I have to end the page tab </page>
in the same line. With <xslt:if>
it doesn't work unfortunately.
Please advise, how can I make this kind of tree fragment structure in order to later extract the node-set using EXSL extension. Thank you.