Re: [xsl] fo:multi-switch or alternative

Subject: Re: [xsl] fo:multi-switch or alternative
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 26 Sep 2012 15:10:33 -0400
At 2012-09-26 15:36 +0200, Jesper Tverskov wrote:
I have a feeling that the table-omit-header-at-break="true" technique
can not be used.

I see you've made it easier for me by putting the "continued..." text in the page footer rather than in the table header. I misunderstood your requirement from your earlier post.


The table that normally stays at page ONE but could continue to page
TWO, should turn a toggle text in the footer of the first page: Let us
say: "Continued over the next page" or "First page only".

Yes, I understand that part.


I have reduced the challenge to the following stylesheet, beginning
with a short and a long text for easy testing:

And I've got a working example below.


            <fo:page-sequence master-reference="document">
                <fo:static-content flow-name="first_first">
                    <fo:block border-top="1pt solid black"
margin-bottom="0.5em"/>
                    <!-- Here we should have a toogle -->
                    <fo:block>Continued over the next page</fo:block>
                    <!-- if ITEMS continue to second page -->
                    <fo:block>First page only</fo:block>
                    <!-- if ITEMS stay on first page -->
                </fo:static-content>

And I tried to say before there is no such thing as a "toggle" in the static world of XSL-FO. The formatting object you cited is for interactive XSL-FO.


My solution below follows the pseudo-code I posted earlier in response to this thread, only retrieving page markers instead of table markers. The algorithm I gave you is sound, if I've understood your requirement. It is a very simple application of markers.

I hope this helps.

. . . . . . . . . . . . . Ken

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:fo="http://www.w3.org/1999/XSL/Format";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl";
exclude-result-prefixes="xs" version="2.0">

<xsl:variable name="text_short" select="'Pellentesque non dui metus.'"/>

    <xsl:variable name="text_long"> Pellentesque non dui metus. Proin
felis urna, mattis iaculis
        ullamcorper sed, faucibus ut sem. Maecenas eleifend imperdiet
augue, et venenatis ipsum
        pellentesque id. Proin at convallis tortor. In sollicitudin
nulla ut eros condimentum cursus
        eu quis ante. Aliquam consectetur tincidunt fringilla.
Suspendisse vitae libero ac risus
        pellentesque lacinia a ut ipsum. Integer pretium nibh a lacus
ullamcorper in sodales leo
        congue. Vestibulum neque velit, sagittis nec sagittis id,
tincidunt id dui. Nam faucibus
        turpis eu velit luctus commodo. Nullam tempor felis et mi
commodo cursus. Aliquam
        sollicitudin ullamcorper venenatis. Phasellus venenatis,
tortor at lobortis adipiscing,
        velit turpis suscipit orci, at tempor dolor ligula nec magna.
Etiam ornare ullamcorper
        mauris, id gravida augue tempus sit amet. Pellentesque non dui
metus. Proin felis urna,
        mattis iaculis ullamcorper sed, faucibus ut sem. Maecenas
eleifend imperdiet augue, et
        venenatis ipsum pellentesque id. Proin at convallis tortor. In
sollicitudin nulla ut eros
        condimentum cursus eu quis ante. Aliquam consectetur tincidunt
fringilla. Suspendisse vitae
        libero ac risus pellentesque lacinia a ut ipsum. Integer
pretium nibh a lacus ullamcorper in
        sodales leo congue. Vestibulum neque velit, sagittis nec
sagittis id, tincidunt id dui. Nam
        faucibus turpis eu velit luctus commodo. Nullam tempor felis
et mi commodo cursus. Aliquam
        sollicitudin ullamcorper venenatis. Phasellus venenatis,
tortor at lobortis adipiscing,
        velit turpis suscipit orci, at tempor dolor ligula nec magna.
Etiam ornare ullamcorper
        mauris, id gravida augue tempus sit amet. Pellentesque non dui
metus. Proin felis urna,
        mattis iaculis ullamcorper sed, faucibus ut sem. Maecenas
eleifend imperdiet augue, et
        venenatis ipsum pellentesque id. Proin at convallis tortor. In
sollicitudin nulla ut eros
        condimentum cursus eu quis ante. Aliquam consectetur tincidunt
fringilla. Suspendisse vitae
        libero ac risus pellentesque lacinia a ut ipsum. Integer
pretium nibh a lacus ullamcorper in
        sodales leo congue. Vestibulum neque velit, sagittis nec
sagittis id, tincidunt id dui. Nam
        faucibus turpis eu velit luctus commodo. Nullam tempor felis
et mi commodo cursus. Aliquam
        sollicitudin ullamcorper venenatis. Phasellus venenatis,
tortor at lobortis adipiscing,
        velit turpis suscipit orci, at tempor dolor ligula nec magna.
Etiam ornare ullamcorper
        mauris, id gravida augue tempus sit amet.Pellentesque non dui
metus. Proin felis urna,
        mattis iaculis ullamcorper sed, faucibus ut sem. Maecenas
eleifend imperdiet augue, et
        venenatis ipsum pellentesque id. Proin at convallis tortor. In
sollicitudin nulla ut eros
        condimentum cursus eu quis ante. Aliquam consectetur tincidunt
fringilla. Suspendisse vitae
        libero ac risus pellentesque lacinia a ut ipsum. Integer
pretium nibh a lacus ullamcorper in
        sodales leo congue. Vestibulum neque velit, sagittis nec
sagittis id, tincidunt id dui. Nam
        faucibus turpis eu velit luctus commodo. Nullam tempor felis
et mi commodo cursus. Aliquam
        sollicitudin ullamcorper venenatis. Phasellus venenatis,
tortor at lobortis adipiscing,
        velit turpis suscipit orci, at tempor dolor ligula nec magna.
Etiam ornare ullamcorper
        mauris, id gravida augue tempus sit amet.Pellentesque non dui
metus. Proin felis urna,
        mattis iaculis ullamcorper sed, faucibus ut sem. Maecenas
eleifend imperdiet augue, et
        venenatis ipsum pellentesque id. Proin at convallis tortor. In
sollicitudin nulla ut eros
        condimentum cursus eu quis ante. Aliquam consectetur tincidunt
fringilla. Suspendisse vitae
        libero ac risus pellentesque lacinia a ut ipsum. Integer
pretium nibh a lacus ullamcorper in
        sodales leo congue. Vestibulum neque velit, sagittis nec
sagittis id, tincidunt id dui. Nam
        faucibus turpis eu velit luctus commodo. Nullam tempor felis
et mi commodo cursus. Aliquam
        sollicitudin ullamcorper venenatis. Phasellus venenatis,
tortor at lobortis adipiscing,
        velit turpis suscipit orci, at tempor dolor ligula nec magna.
Etiam ornare ullamcorper
        mauris, id gravida augue tempus sit amet. </xsl:variable>

<xsl:variable name="text" select="$text_short"/>

<xsl:template name="start" match="/">
<fo:root font-size="14pt">
<fo:layout-master-set>
<fo:simple-page-master master-name="first"
page-height="297mm" page-width="210mm"
margin="1in 1in 1in 1in">
<fo:region-body margin-bottom="2cm"/>
<fo:region-after region-name="first_first" extent="2.3cm"/>
</fo:simple-page-master>


                <fo:simple-page-master master-name="rest"
page-height="297mm" page-width="210mm"
                    margin="1in 1in 1in 1in">
                    <fo:region-body margin-bottom="2cm"/>
                    <fo:region-after region-name="rest_rest" extent="2.3cm"/>
                </fo:simple-page-master>

                <fo:page-sequence-master master-name="document">
                    <fo:repeatable-page-master-alternatives>
                        <fo:conditional-page-master-reference
page-position="first"
                            master-reference="first"/>
                        <fo:conditional-page-master-reference
page-position="rest"
                            master-reference="rest"/>
                    </fo:repeatable-page-master-alternatives>
                </fo:page-sequence-master>
            </fo:layout-master-set>

            <fo:page-sequence master-reference="document">
                <fo:static-content flow-name="first_first">
                    <fo:block border-top="1pt solid black"
margin-bottom="0.5em"/>
<!-- Jesper's requirement
                    <!-\- Here we should have a toogle -\->
                    <fo:block>Continued over the next page</fo:block>
                    <!-\- if ITEMS continue to second page -\->
                    <fo:block>First page only</fo:block>
                    <!-\- if ITEMS stay on first page -\->
-->
<!-- Ken's suggestion-->
                  <fo:block>
                    <fo:retrieve-marker retrieve-class-name="continued"
                        retrieve-position="last-starting-within-page"/>
                    <fo:retrieve-marker retrieve-class-name="firstonly"
                        retrieve-position="last-starting-within-page"/>
                  </fo:block>
                </fo:static-content>

                <fo:static-content flow-name="rest_rest">
                    <fo:block border-top="1pt solid black"
margin-bottom="0.5em"/>
                    <fo:block>END of DOCUMENT</fo:block>
                </fo:static-content>

                <fo:flow flow-name="xsl-region-body">
                    <fo:block>
                      <!--the following markers are used for a long table-->
                      <fo:marker marker-class-name="continued"
                        >Continued over the next page</fo:marker>
                      <fo:marker marker-class-name="firstonly"/>
                    </fo:block>

                    <fo:table border="1pt solid black">
                        <fo:table-header>
                            <fo:table-row>
                                <fo:table-cell>
                                    <fo:block font-size="16pt"
font-weight="bold"
                                        margin-bottom="0.5em">ITEMS:</fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-header>
                        <fo:table-body>
                            <fo:table-row>
                                <fo:table-cell>
                                    <fo:block>
                                        <xsl:value-of select="$text"/>
                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-body>
                    </fo:table>

                    <fo:block>
                      <!--the following markers are used for a short table-->
                      <fo:marker marker-class-name="continued"/>
                      <fo:marker marker-class-name="firstonly"
                        >First page only</fo:marker>
                    </fo:block>

                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>



--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

Current Thread