You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "Carsten B." <c....@xdot.de> on 2009/07/16 18:11:05 UTC

Sobtotal per Page

Hi,

i searching about 2 days now. I need a subtotal on each page.

I have an unknown ordercount with unknown postition:

Example:
<--- Page start --->
Order: 123
Position 1: Art Nr. ...   Price
Position 2: Art Nr. ...   Price
Position 3: Art Nr. ...   Price
                                 Total: ...
Order: 124
Position 1: Art Nr. ...   Price
                                 Total: ...

# Insert subtotal here
<--- Page End --->

I need a subtotal on each page, that prints the the values of each totals on
this page + all totals on previous pages.


Here are some code snipplets.

<fo:static-content flow-name="Footer">
        <fo:block-container position="absolute" left="4.65in" top="40%"
height="1in" width="100%">
            <fo:block font-size="9pt">Zwischensumme</fo:block>
              <fo:retrieve-marker retrieve-class-name="title"
                retrieve-position="first-starting-within-page"
                retrieve-boundary="page"/>
        </fo:block-container>
</fo:static-content>

[...]

<fo:table-cell>
    <fo:block text-align="right"
              margin-top="2mm">
        <fo:marker marker-class-name="title" >
                <xsl:value-of select="$totalsum"/>
        <!--- I need the subtotal on at this place --->
        </fo:marker>
        <fo:inline font-weight="bold">
            <xsl:value-of
                    select="format-number(.//Auftragssumme, '#.00')"/>
            &#160; EUR
            <!--- Update $totalsum --->
            <xsl:variable name="totalsum"
                          select="format-number($totalsum +
.//Auftragssumme, '#.00')"/>
        </fo:inline>
    </fo:block>
</fo:table-cell>


The problem is, that I don't know how i get the value from $totalsum into my
footer. The second thing is, that i need to update $totalsum before i print
my subtotal.


I begging on my knees!

Thnks for any informations :)


Regard from Germany, 

Carsten
-- 
View this message in context: http://www.nabble.com/Sobtotal-per-Page-tp24519516p24519516.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Sobtotal per Page

Posted by "Christopher R. Maden" <cr...@maden.org>.
Carsten B. wrote:
> Is this in possible in any way. I would do something like that in JS or
> Java.

This is the root of your problem.  XSLT is not like JS or Java.  Those
languages are procedural, while XSLT is a declarative language.

Think about this processing model: the XSLT processor walks over the
input XML, executing the appropriate templates for each node it finds.
Now think about this model: the XSLT processor collects all the nodes in
the input XML, then fires up a separate thread for every single one to
find and execute the appropriate template.  The results should be the same.

That means that your XSLT needs to be able to determine the subtotal for
the 30,000th item in complete ignorance of what the subtotal was for the
29,999th item.

~Chris
-- 
Chris Maden, text nerd  <URL: http://crism.maden.org/ >
“All I ask of living is to have no chains on me,
 And all I ask of dying is to go naturally.” — Laura Nyro
GnuPG Fingerprint: C6E4 E2A9 C9F8 71AC 9724 CAA3 19F8 6677 0077 C319

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Sobtotal per Page

Posted by "Carsten B." <c....@xdot.de>.
Thanks for this answer, Chris.


Christopher R. Maden wrote:
> 
> You are calling a template called “getSubtotal” and don’t have a
> template called “getSubtotal.”  Hence, the template could not be found.
> 

I understand now. My mistake was i defined the template "getSubtotal" und my
main template.


I would recommend making a very simple XSLT that produces plain text or
HTML from your data, with a running subtotal at every section.  That
should point the way to doing it in FO.


Christopher R. Maden wrote:
> 
> You may also consider raising this question on the xsl-list, as it’s
> independent of FOP.  However, the very helpful people there are also
> very busy, so prepare a stripped-down example that demonstrates your
> problem.  (You may also find that preparing such an example helps you to
> solve it yourself.)
> 

Sorry, did not know I was wrong. So this will me my last question (Sorry,
but after this we have "hopefully" solved my Problem).



Christopher R. Maden wrote:
> 
> When you retrieve a marker with last-ending-within-page, you’ll get the
> last one on that page.  So if you generated five subtotal markers on the
> page, you’ll just get the fifth one.
> 

Is the a possibility to return a value from a template?

I would like to implement a rekursive "service". It shall lokk like this. 

3 Oders:
1 OderSum: 1
2 OderSum: 2
#PAGEBREAK#
3 OrdeSum: 3
$total = 0

I go through my xml with a for-each.

<!-- Call template -->
     $total = $total + "OrderSum1";
     <!-- Call retrieve marker to check if it is the last OrdeSum on a page
-->
     RETURN $total into $total from for-each
<!-- Call template end -->


Repeat from here if there are OderSums left.

So i would have:
Run: 
1. Walk through: $total (for-each)=0    
     1. $OrderSum=1 
     2. $total (Template)=$total (Teplate)+$Ordersum (after this 1)
     3. RETURN total 
2. Walk through: $total (for-each)=1
     1. $OrderSum=2 
     2. $total (Template)=$total (Teplate)+$Ordersum (after this 3)
     3. RETURN total 
<!-- Pagebreak -->
    Call retrieve-marker with param $total (for-each) and print it in my
footer (Printed: Odersum: 3)
3. Walk through: $total (for-each)=3
     1. $OrderSum=2 
     2. $total (Template)=$total (Teplate)+$Ordersum (after this 5)
     3. RETURN total 
<!-- Pagebreak -->
    Call retrieve-marker with param $total (for-each) and print it in my
footer (Printed: Odersum: 5)


I hope you could follow my thoughts.

Is this in possible in any way. I would do something like that in JS or
Java.
-- 
View this message in context: http://www.nabble.com/Sobtotal-per-Page-tp24519516p24534811.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Sobtotal per Page

Posted by "Christopher R. Maden" <cr...@maden.org>.
Carsten B. wrote:
> I finally i found something. But I have a problem in calling the template.
> What ist wrong, can't figure it out.
> 
> <xsl:template mode="do-sum" match="Auftrag">
> 
>                         <fo:block font-size="9pt">Zwischensumme:
>                             ### Call Template ####
>                             <xsl:call-template name="getSubtotal"/>
>                         </fo:block>
> 
> I don't know what wrong and where zo put my templates. Everytime I get
> "the-template-could-not-be-found".

You are calling a template called “getSubtotal” and don’t have a
template called “getSubtotal.”  Hence, the template could not be found.

I would recommend making a very simple XSLT that produces plain text or
HTML from your data, with a running subtotal at every section.  That
should point the way to doing it in FO.

You may also consider raising this question on the xsl-list, as it’s
independent of FOP.  However, the very helpful people there are also
very busy, so prepare a stripped-down example that demonstrates your
problem.  (You may also find that preparing such an example helps you to
solve it yourself.)

> I skipped dealing with markers, because I couldn't figure out how to call
> the "last marker" on a page.

When you retrieve a marker with last-ending-within-page, you’ll get the
last one on that page.  So if you generated five subtotal markers on the
page, you’ll just get the fifth one.

~Chris
-- 
Chris Maden, text nerd  <URL: http://crism.maden.org/ >
“All I ask of living is to have no chains on me,
 And all I ask of dying is to go naturally.” — Laura Nyro
GnuPG Fingerprint: C6E4 E2A9 C9F8 71AC 9724 CAA3 19F8 6677 0077 C319

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


AW: Sobtotal per Page

Posted by Georg Datterl <ge...@geneon.de>.
Hi Carsten,

I don't think you can skip the marker part. You don't have a way to know, when the table will be broken to the next page. Without that, you don't know which lines to add up. You have two problems. One is, how to calculate the values. That's an XSL Problem and can be solved with the template below, I guess. But still, you get "running-sum" for each line and have to use (second problem:) a marker to grab the last "running-sum" on the page to display in the footer. 

Regards,
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 
-----Ursprüngliche Nachricht-----
Von: Carsten B. [mailto:c.buehler@xdot.de] 
Gesendet: Freitag, 17. Juli 2009 12:11
An: fop-users@xmlgraphics.apache.org
Betreff: Re: Sobtotal per Page


Hi,

I finally i found something. But I have a problem in calling the template.
What ist wrong, can't figure it out.

<!--- Template to calculate Subtotals --> <xsl:template mode="do-sum" match="Auftrag">
            <xsl:param name="sum" select="0"/>
            <xsl:variable name="running-sum"
                          select="number(translate($sum + number(Auftragssumme),'.',''))"/>
            <xsl:choose>
                <xsl:when test="following-sibling::Rechnung">
                    <xsl:apply-templates mode="do-sum"
select="following-sibling::Auftrag[1]">
                        <xsl:with-param name="sum" select="$running-sum"/>
                    </xsl:apply-templates>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="format-number($running-sum,
'#.##0,00', 'numfrmt')"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template name="getSubtotal">
                Subtotal:
               <!-- <xsl:apply-templates mode="do-sum"
select="/Root/Rechnung/Auftrag[1]"/>-->
        </xsl:template>
<!-- End Template calculating subtotals -->




            <fo:layout-master-set>
                <fo:simple-page-master master-name="Rechnung"
page-width="8.5in" page-height="11in">

                    <fo:region-body region-name="PageBody"
margin-top="1.5in" margin-left="0.8in"
                                    margin-bottom="0.8in"/>
                    <fo:region-before region-name="Header" extent="1.2in"
margin-left="0.8in"/>
                    <fo:region-after region-name="Footer" extent="1in"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="Rechnung">
                <!-- Rechnungsnumemr und Seitenzahl-->
                <fo:static-content flow-name="Header">
                  [...]
                </fo:static-content>

                <!-- Footer -->
                <!--<fo:static-content flow-name="Footer"> -->
                <fo:static-content flow-name="Footer">
                      <fo:block-container position="absolute" left="4.65in"
top="40%" height="1in" width="100%">
                        <!--  <fo:retrieve-marker retrieve-class-name="title"
                       retrieve-position="first-starting-within-page"
                       retrieve-boundary="page"/> -->

                        <fo:block font-size="9pt">Zwischensumme:
                            ### Call Template ####
                            <xsl:call-template name="getSubtotal"/>
                        </fo:block>

                    </fo:block-container>
                </fo:static-content>
                <!--</fo:static-content>-->
                <!-- Footer Ende -->


I don't know what wrong and where zo put my templates. Everytime I get "the-template-could-not-be-found".


I skipped dealing with markers, because I couldn't figure out how to call the "last marker" on a page.

Sorry about this nooby questions.


--
View this message in context: http://www.nabble.com/Sobtotal-per-Page-tp24519516p24531834.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Sobtotal per Page

Posted by "Carsten B." <c....@xdot.de>.
Hi,

I finally i found something. But I have a problem in calling the template.
What ist wrong, can't figure it out.

<!--- Template to calculate Subtotals -->
<xsl:template mode="do-sum" match="Auftrag">
            <xsl:param name="sum" select="0"/>
            <xsl:variable name="running-sum"
                          select="number(translate($sum +
number(Auftragssumme),'.',''))"/>
            <xsl:choose>
                <xsl:when test="following-sibling::Rechnung">
                    <xsl:apply-templates mode="do-sum"
select="following-sibling::Auftrag[1]">
                        <xsl:with-param name="sum" select="$running-sum"/>
                    </xsl:apply-templates>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="format-number($running-sum,
'#.##0,00', 'numfrmt')"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template name="getSubtotal">
                Subtotal:
               <!-- <xsl:apply-templates mode="do-sum"
select="/Root/Rechnung/Auftrag[1]"/>-->
        </xsl:template>
<!-- End Template calculating subtotals -->




            <fo:layout-master-set>
                <fo:simple-page-master master-name="Rechnung"
page-width="8.5in" page-height="11in">

                    <fo:region-body region-name="PageBody"
margin-top="1.5in" margin-left="0.8in"
                                    margin-bottom="0.8in"/>
                    <fo:region-before region-name="Header" extent="1.2in"
margin-left="0.8in"/>
                    <fo:region-after region-name="Footer" extent="1in"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="Rechnung">
                <!-- Rechnungsnumemr und Seitenzahl-->
                <fo:static-content flow-name="Header">
                  [...]
                </fo:static-content>

                <!-- Footer -->
                <!--<fo:static-content flow-name="Footer"> -->
                <fo:static-content flow-name="Footer">
                      <fo:block-container position="absolute" left="4.65in"
top="40%" height="1in" width="100%">
                        <!--  <fo:retrieve-marker
retrieve-class-name="title"
                       retrieve-position="first-starting-within-page"
                       retrieve-boundary="page"/> -->

                        <fo:block font-size="9pt">Zwischensumme:
                            ### Call Template ####
                            <xsl:call-template name="getSubtotal"/>
                        </fo:block>

                    </fo:block-container>
                </fo:static-content>
                <!--</fo:static-content>-->
                <!-- Footer Ende -->


I don't know what wrong and where zo put my templates. Everytime I get
"the-template-could-not-be-found".


I skipped dealing with markers, because I couldn't figure out how to call
the "last marker" on a page.

Sorry about this nooby questions.


-- 
View this message in context: http://www.nabble.com/Sobtotal-per-Page-tp24519516p24531834.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Sobtotal per Page

Posted by "Christopher R. Maden" <cr...@maden.org>.
J.Pietschmann wrote:
> On 16.07.2009 18:11, Carsten B. wrote:
>> i searching about 2 days now. I need a subtotal on each page.
> 
> That's known to be a difficult problem.

In this case, I think it’s tractable.  In fact, I think Carsten might be
having problems with the XSLT rather than the FO.

The use of marker is the right approach; each row should have a marker
whose value is the running total to that point.  Carsten’s comment
(“update $totalsum”) indicates the usual problem with procedural coding;
the totalsum should be calculated afresh at each point.

The value of the last marker on the page can be retrieved in the footer
pretty easily, once that problem is addressed.

~Chris
-- 
Chris Maden, text nerd  <URL: http://crism.maden.org/ >
“All I ask of living is to have no chains on me,
 And all I ask of dying is to go naturally.” — Laura Nyro
GnuPG Fingerprint: C6E4 E2A9 C9F8 71AC 9724 CAA3 19F8 6677 0077 C319

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Sobtotal per Page

Posted by "J.Pietschmann" <j3...@yahoo.de>.
On 16.07.2009 18:11, Carsten B. wrote:
> i searching about 2 days now. I need a subtotal on each page.

That's known to be a difficult problem.

>          <fo:marker marker-class-name="title">
>                  <xsl:value-of select="$totalsum"/>
>          <!--- I need the subtotal on at this place --->
>          </fo:marker>
Here's the rub: the transformation stage and the formatting
stage are two separate processes. There is no way the
transformation can know which positions are put on a page
by the formatting process, and the layout process can't add
up numbers. That's the way it is.

You can try one of the following approaches:
- If the positions all take up the same vertical space, e.g.
  a single line or two lines, you can paginate them in the
  transformation (look up "grouping by position"), and you
  can calculate the subtotal in the transformation.
- You can use a two pass approach: run the whole process using
  fixed dummy subtotals, extract the positions on the pages
  from the result, then run the process again with a
  transformation with explicit pagination. The area tree output
  or the new intermediate format (trunk only) make it relatively
  easy to get which positions are on which pages.
- Run the transformation using fixed dummy subtotals, then use
  the intermediate format (trunk only) to hook in some
  additional code which calculates the real subtotals and replace
  the dummy values. You will probably have to do some extended
  magic to get the numbers right aligned.

J.Pietschmann

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org