[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Grouping issue - multiple page break locations

Subject: RE: Grouping issue - multiple page break locations
From: "Roger Glover" <glover_roger@xxxxxxxxx>
Date: Mon, 3 Feb 2003 17:47:49 -0600
page xsl
Just saw Francis' 2(!) postings.  I offer this as a third similar
alternative.  It leans more toward simple expressions and more granular
templates, but it does not handle the "empty text" -> "no para" case that
francis does handle.  Neither of us seem to handle the case of an input para
that spans 2 page breaks instead of one.

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.
>
> My source XML is structured like the following:
>
--- snip ---
>
> The page element in the souce can occur as a child of the root
> element or as
> a child of the para element.  When it occurs within the para
> element, I need
> to close and then open the para element.
>
> What I want to achieve is a page based hierarchy such as:
>
--- snip ---
>
> If anyone could help, it would be greatly appreciated!

Keep in mind that it is most effective to structure templates according to
the output format.  This tranform builds the book containing the pages
containing (here's the tricky part) the appropriate paragraphs.  Try
something like this:

=========================================
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
	<xsl:apply-templates select="book"/>
</xsl:template>

<xsl:template match="book">
    <xsl:copy>
        <!-- finds all pages and reinserts them at book-level -->
        <xsl:apply-templates select="page | para/page"/>
    </xsl:copy>
</xsl:template>

<!-- matches all book-level pages -->
<xsl:template match="book/page">
    <xsl:copy>
        <xsl:copy-of select="@number"/>
        <!-- if next element is a para add it to this page -->
        <xsl:apply-templates
            select="following-sibling::*[position()=1 and name()='para']"
            mode="until-next-page"
        />
    </xsl:copy>
</xsl:template>

<!-- matches all para-level pages -->
<xsl:template match="para/page">
    <xsl:copy>
        <xsl:copy-of select="@number"/>
        <!-- gathers all text nodes after page into a para -->
        <para><xsl:apply-templates
select="following-sibling::text()"/></para>
        <!-- if next element after parent para is a para add it to this
page -->
        <xsl:apply-templates
            select="../following-sibling::*[position()=1 and name()='para']"
            mode="until-next-page"
        />
    </xsl:copy>
</xsl:template>

<!-- matches all paras containing a page -->
<xsl:template match="para[page]" mode="until-next-page">
    <!-- gathers all text nodes before page into a para -->
    <para><xsl:apply-templates
select="page/preceding-sibling::text()"/></para>
</xsl:template>

<!-- matches all paras not containing a page -->
<xsl:template match="para[not(page)]" mode="until-next-page">
    <!-- copy this para into enclosing result page -->
    <xsl:copy-of select="."/>
    <!-- if next element is a para add it to enclosing result page -->
    <xsl:apply-templates
        select="following-sibling::*[position()=1 and name()='para']"
        mode="until-next-page"
    />
</xsl:template>

<!-- removes "ignorable" white space -->
<xsl:template match="text()">
    <xsl:value-of select="normalize-space()"/>
</xsl:template>
=========================================

-- Roger Glover
   glover_roger@xxxxxxxxx



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.