trying to use xsl:choose to test for last page

Discussion in 'XML' started by freefly_xml, May 15, 2006.

  1. freefly_xml

    freefly_xml Guest

    I want to test to see if I am on the last page of a document. In this
    example it is an invoice. I want to print a different table in REGION
    AFTER when I am on the last page. I have tried many variations, no luck
    yet. It seems like it should be an easy thing to do with xsl:choose.

    Any ideas? Here is one of my attempts.
    More detail of what the xml, xsl and pdf look like are here:
    http://www.bangboompow.com/xml/invoice/


    I am trying to test the field value in the footer area like this:

    <xsl:choose>
    <xsl:when test="document_end = 'TRUE'">
    <fo:block font-size="10pt" font-weight="bold">
    LAST PAGE
    </fo:block>
    </xsl:when>
    <xsl:eek:therwise>
    <fo:block font-size="10pt" font-weight="bold">
    not the last page
    </fo:block>
    </xsl:eek:therwise>
    </xsl:choose>

    I am trying to set the value of the field in the detail line loop like
    this:

    <xsl:if test="position() = last()">
    <xsl:variable name="document_end" select="'TRUE'" />
    </xsl:if>
     
    freefly_xml, May 15, 2006
    #1
    1. Advertising

  2. > <xsl:if test="position() = last()">
    > <xsl:variable name="document_end" select="'TRUE'" />
    > </xsl:if>


    Position doesn't refer to page number, but to position in a set of nodes
    returned by an XPath expression.

    Nothing in XSLT knows about the concept of "pages" per se.

    If the XML language you're working in has a <page> element or something
    equivalent to it, you could test for whether you are within the last
    such element.

    But I presume you're looking for something that will dynamically lay out
    the document with an awareness of pagination. That isn't XSLT's job;
    that's the sort of thing which the next stage of processing (XSL-FO, for
    example) would handle.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, May 15, 2006
    #2
    1. Advertising

  3. freefly_xml

    Andy Dingley Guest

    freefly_xml wrote:
    > I want to test to see if I am on the last page of a document.


    This is really hard to do in any language remotely like XSLT. The
    problem is that XSLT is largely data-centric, not layout-centric. You
    need to think of a way of recognising "on the last page" for your
    document that can be evaluated simply by looking at the data elements
    in the source XML. In many cases this simply isn't possible. Actually
    coding the thing as an XPath expression might be the easy bit.

    Sometimes, in pathological cases, you have to perform the XML => XSL:FO
    transformation (probably by XSLT) first. Once you're into XSL:FO then
    you've fixed the layout, implied the page layout and you can start
    looking at concepts like page number. Only then can you start
    identifying "last page" -- probably by another XSLT identity transform
    turning XSL:FO into XSL:FO, but with a minor template rule in there
    identifying some condition and making a minor change.
     
    Andy Dingley, May 16, 2006
    #3
  4. freefly_xml

    Peter Flynn Guest

    freefly_xml wrote:
    > I want to test to see if I am on the last page of a document.


    As Joe and Andy have explained, you can't easily do this unless
    you are programming within a page-aware formatter. Normally this
    kind of thing is handled by the print-formatter stylesheet.

    Maybe within your template for Detail_Line you could add at
    the end something like

    <xsl:if test="not(following-sibling::Detail_line)">
    stuff to do on last page
    </xsl:if>

    on the principle that if you're processing the last
    Detail_Line, you're probably on the last page...

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
     
    Peter Flynn, May 16, 2006
    #4
  5. freefly_xml

    freefly_xml Guest

    A working way to create a different footer for the last page of a
    document with xslt.

    In the looping of the detail lines test for the last line and set a
    marker:

    <xsl:choose>
    <xsl:when test="position() = last()">
    <fo:marker marker-class-name="footer-marker">
    <fo:block>LAST PAGE</fo:block>
    </fo:marker>
    </xsl:when>
    <xsl:eek:therwise>
    <fo:marker marker-class-name="footer-marker">
    <fo:block>Continued...</fo:block>
    </fo:marker>
    </xsl:eek:therwise>
    </xsl:choose>

    then retrieve the marker in the region-after with this:

    <fo:retrieve-marker retrieve-position="last-ending-within-page"
    retrieve-class-name="footer-marker" />
     
    freefly_xml, May 16, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruthless

    xsl:choose

    Ruthless, Dec 26, 2003, in forum: XML
    Replies:
    2
    Views:
    471
    Ruthless
    Dec 27, 2003
  2. Prabh

    Pick/Choose XML from XSL

    Prabh, Dec 1, 2004, in forum: XML
    Replies:
    3
    Views:
    449
    Morris M. Keesan
    Dec 4, 2004
  3. Replies:
    1
    Views:
    3,653
    A. Bolmarcich
    May 27, 2005
  4. Anthony Irwin

    Trying to choose between python and java

    Anthony Irwin, May 15, 2007, in forum: Python
    Replies:
    34
    Views:
    847
    Bruno Desthuilliers
    Jul 16, 2007
  5. michael75
    Replies:
    0
    Views:
    1,853
    michael75
    Aug 3, 2010
Loading...

Share This Page