By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

XSL Group by and sub totals

P: n/a
Hi I have the following FO XSL document with the following data

I am trying to add sub totals for each group in a XSL document but
cannnot seem to work it out!

Output would be something like:-

Area 1
--- Name 1.1
--- Name 1.2
--- Name 3.1
Sub total = 3
Area 2
--- Name 2.1
--- Name 2.2
Sub total = 2

Grand total = 5

Can anyone help?
##### BEGIN XSL DOC ######

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- defines the layout master -->
<fo:layout-master-set>
<fo:simple-page-master master-name="first" page-height="21cm"
page-width="29.7cm" margin-top="1cm" margin-bottom="1cm"
margin-left="1.5cm" margin-right="1.5cm">
<fo:region-body margin-top="15mm" margin-left="0mm"
margin-right="0mm" margin-bottom="0mm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- starts actual layout -->
<fo:page-sequence master-reference="first">
<!--start - page body-->
<fo:flow flow-name="xsl-region-body" font-size="9pt">
<!--wrapper table-->
<fo:block>
<fo:table margin-top="10mm" table-layout="fixed"
width="100%">
<fo:table-column
column-width="proportional-column-width(1)"/>
<fo:table-column
column-width="proportional-column-width(1)"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell padding="3pt"
border-bottom-style="solid" border-bottom-color="#000000"
border-bottom-width="1px">
<fo:block>LLSC</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt"
border-bottom-style="solid" border-bottom-color="#000000"
border-bottom-width="1px">
<fo:block>Nextstep site</fo:block>
</fo:table-cell>
</fo:table-row>
<xsl:for-each select="Root/Data">
<fo:table-row>
<fo:table-cell padding="3pt"
border-bottom-style="solid" border-bottom-color="#EEEEEE"
border-bottom-width="1px">
<fo:block>
<xsl:value-of select=".//LLSCName"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt"
border-bottom-style="solid" border-bottom-color="#EEEEEE"
border-bottom-width="1px">
<fo:block padding-left="10mm">
<xsl:value-of select=".//NextstepName"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
<!--End - page body-->
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>

##### END XSL DOC ######
##### BEGIN XML DOC ######

<?xml version="1.0" standalone="yes"?>
<Root>
<Data>
<LLSCName>Area 1</LLSCName>
<NextstepName>Name 1.1</NextstepName>
</Data>
<Data>
<LLSCName>Area 1</LLSCName>
<NextstepName>Name 2.1</NextstepName>
</Data>
<Data>
<LLSCName>Area 1</LLSCName>
<NextstepName>Name 3.1</NextstepName>
</Data>
<Data>
<LLSCName>Area 2</LLSCName>
<NextstepName>Name 2.1</NextstepName>
</Data>
<Data>
<LLSCName>Area 2</LLSCName>
<NextstepName>Name 2.2</NextstepName>
</Data>
</Root>

##### END XML DOC ######

Mar 20 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Rippo wrote:
I am trying to add sub totals for each group in a XSL document but
cannnot seem to work it out!

Output would be something like:-

Area 1
--- Name 1.1
--- Name 1.2
--- Name 3.1
Sub total = 3
Area 2
--- Name 2.1
--- Name 2.2
Sub total = 2

Grand total = 5

Can anyone help?


To my mind, most Arithmetic in XSLT is a bit of a pain. It may not
apply to your case, but if your original XML is generated from
a relational database, don't forget that the database engine is
(almost certainly) able to do all this and present it to you
as a VIEW.

Much easier, in my experience.

Mar 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.