[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Restrictind a set of notes to within a group


Subject: Re: [xsl] Restrictind a set of notes to within a group
From: "Mark" <mark@xxxxxxxxxxxx>
Date: Thu, 19 Apr 2012 07:39:02 -0700

Ken and Martin,
I should have seen that (red-faced here)
Thanks,
Mark

-----Original Message----- From: G. Ken Holman
Sent: Thursday, April 19, 2012 7:24 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx ; xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Restrictind a set of notes to within a group


At 2012-04-19 07:17 -0700, Mark wrote:
have an xml file like
<Month>
   <Date day=C"b,B1C"b,B>
       <Session task=C"b,Btask1C"b,B>
           <Notes hours-worked=C"b,B1.5C"b,B/>
       </Session>
       <Session task=C"b,Btask2C"b,B>
           Notes hours-worked=C"b,B5C"b,B/>
       <Session task=C"b,Btask1C"b,B>
           <Notes hours-worked=C"b,B3C"b,B/>
       </Session>
   </Date>
   <Date day=C"b,B2C"b,B>
       ....
   </Date>
</Month>
For the month, I want to sum all the hours-worked for each task:

I have tried several expressions, but failed. This gives me the total hours worked on all tasks rather than each individual task:
<xsl:for-each-group select="Date/Session" group-by="@task">
<xsl:for-each select=".">
<fo:block xsl:use-attribute-sets="subdiv2">
<xsl:value-of select="@task"/>
<xsl:text> (</xsl:text>
<xsl:value-of select="format-number(sum(../../Date/Session/Notes/@hours-worked), '.00')"/>
<xsl:text>) </xsl:text>
</fo:block>
</xsl:for-each>
</xsl:for-each-group>
How do I restrict the total to just the hours-worked on each specific task?

You have to work with those sessions that are in the current group. Rather, you are looking at all sessions and getting the total sum.

Use:

  <xsl:value-of
select="format-number(sum(current-group()/Notes/@hours-worked),'.00')"/>

You've already correctly created the groups, you
just aren't using them having created them.

BTW, the <xsl:for-each select="."> is meaningless
and does nothing except render your context list
to be only a single item which is not
useful.  Although you don't need the set of
groups in your solution, not having that
<xsl:for-each> would give you more information
about the current group within the set of groups.

I hope this helps.

. . . . . . . . . Ken

--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- May 2012
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
Keywords