[Home] [By Thread] [By Date] [Recent Entries]
[RETRY 3]
At 2014-07-04 10:56 -0400, I wrote: At 2014-07-04 14:43 +0000, Geert Bormans geert@xxxxxxxxxxxxxxxxxxx wrote:Now I want to break the document per page, reconstructing the structure My solution does not offer the advanced features that Gerrit suggested, nor is it as elegant a solution as he describes ... it is more brute force and probably slower in execution. It is simply a modification of the identity transform using ">>" and "<<", but I think it is giving the correct results. I hope it helps. . . . . . . . . Ken t:\ftemp>type geert.xml
<?xml version="1.0" encoding="UTF-8"?>
<book>
<title>...</title>
<section no="1">
<para>aaa<pb/>bbb</para>
</section>
<section no="2">
<para>2-1</para>
<para>ccc<pb/>ddd<pb/>eee</para>
<para>2-3</para>
<subsection>
<para>fff<pb/>ggg<span>hhh<pb/>jjj</span>kkk<pb/>mmm</para>
</subsection>
<pb/>
<para>2-5</para>
</section>
<section>
<para>No breaks</para>
</section>
</book>t:\ftemp>call xslt2 geert.xml geert.xsl geert.out.xml t:\ftemp>type geert.out.xml <?xml version="1.0" encoding="UTF-8"?><book> <title>...</title> <section no="1"> <para>aaa</para></section> <pb/> <section no="1"><para>bbb</para> </section><section no="2"> <para>2-1</para> <para>ccc</para></section> <pb/> <section no="2"><para>ddd</para></section> <pb/> <section no="2"><para>eee</para> <para>2-3</para> <subsection> <para>fff</para></subsection></section> <pb/> <section no="2"><subsection><para>ggg<span>hhh</span></para></subsection></section> <pb/> <section no="2"><subsection><para><span>jjj</span>kkk</para></subsection></section> <pb/> <section no="2"><subsection><para>mmm</para> </subsection> </section> <pb/> <section no="2"> <para>2-5</para> </section><section> <para>No breaks</para> </section> </book> t:\ftemp>type geert.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xsd" version="2.0"> <xsl:template match="book"> <xsl:copy> <xsl:copy-of select="@*"/> <!--everything before the first section--> <xsl:copy-of select="node()[. << current()/section[1] ]"/> <!--prepare to revisit all sections--> <xsl:variable name="sections" select="section"/> <xsl:choose> <!--simply copy the content if there are no page-breaks--> <xsl:when test="empty(.//pb)"> <xsl:copy-of select="$sections"/> </xsl:when> <xsl:otherwise> <!--copy down from the apex repeatedly for each pb--> <xsl:for-each select=".//pb"> <xsl:apply-templates select="$sections" mode="section"> <xsl:with-param tunnel="yes" name="after" select="preceding::pb[1]"/> <xsl:with-param tunnel="yes" name="before" select="."/> <xsl:with-param tunnel="yes" name="ancestors" select="ancestor::* | preceding::pb[1]/ancestor::*"/> </xsl:apply-templates> <xsl:text>
</xsl:text> <pb/> <xsl:text>
</xsl:text> </xsl:for-each> <!--copy everything after the last page break--> <xsl:apply-templates select="$sections" mode="section"> <xsl:with-param tunnel="yes" name="after" select="(.//pb)[last()]"/> <xsl:with-param tunnel="yes" name="ancestors" select="(.//pb)[last()]/ancestor::*"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> <!--everything after the last section--> <xsl:copy-of select="node()[. >> current()/section[last()] ]"/> </xsl:copy> </xsl:template> <xsl:template match="@*|node()" mode="#default section">
<xsl:param tunnel="yes" name="after"/>
<xsl:param tunnel="yes" name="before"/>
<xsl:param tunnel="yes" name="ancestors" as="element()*"/>
<xsl:choose>
<xsl:when test="( . intersect $ancestors ) or
( not($after) and not($before) ) or
( not($after) and . << $before ) or
( . >> $after and not($before) ) or
( . >> $after and . << $before )">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template></xsl:stylesheet> t:\ftemp>rem Done!
|

Cart



