xsl-list
[Top] [All Lists]

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

2012-04-19 09:24:37
At 2012-04-19 07:17 -0700, Mark wrote:
have an xml file like
<Month>
   <Date day=â??1â??>
       <Session task=â??task1â??>
           <Notes hours-worked=â??1.5â??/>
       </Session>
       <Session task=â??task2â??>
           Notes hours-worked=â??5â??/>
       <Session task=â??task1â??>
           <Notes hours-worked=â??3â??/>
       </Session>
   </Date>
   <Date day=â??2â??>
       ....
   </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(_at_)CraneSoftwrights(_dot_)com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--