Hi Matteo,
M V wrote:
I've run into some problems with grouping that I hope someone can help
me through. I've read just about every article and FAQ on grouping
that I've been able to locate. I've also been through Michael Kay's
and Jeni Tennison's books. I haven't been able to apply any of the
examples successfully to this particular variation.
You only have two problems with this, the fact that page elements are
mis-nested, and the fact that the follow-on paras need to be treated
specially. You'll find something like the following works:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="book">
<book>
<!-- find first page - we have to step through to avoid nesting
problems -->
<xsl:apply-templates select="descendant::page[1]"/>
</book>
</xsl:template>
<xsl:template match="page">
<!-- create a page element -->
<page number="{(_at_)number}">
<!-- and turn any continuation text into a new paragraph -->
<xsl:if test="normalize-space(following-sibling::text()) != ''">
<para>
<xsl:value-of select="following-sibling::text()"/>
</para>
</xsl:if>
<!-- find all the paragraphs for *this* page, which could be
children or following elements -->
<xsl:apply-templates select="(child::para |
following::para)[preceding::page[1]/@number = current()/@number]"/>
</page>
<!-- now step through to next page -->
<xsl:apply-templates select="following::page[1]"/>
</xsl:template>
<xsl:template match="para">
<para>
<!-- only print out first text node, in case of embedded page
element -->
<xsl:value-of select="child::text()[1]" />
</para>
</xsl:template>
</xsl:stylesheet>
Hope this helps -
Francis.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list