Francis Norton wrote:
<something excessively complicated>
this solution solves the same two problems but without the unnecessary
complexity of my first clumsy effort
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="book">
<book>
<!-- find all the pages, ignore how they're nested in each other
or in paras -->
<xsl:apply-templates select="descendant::page"/>
</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>
</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>
That's better!
Francis.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list