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
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.
<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.
-- 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Restrictind a set of note, G. Ken Holman | Thread | [xsl] XSLT 1.0 n-queens and questio, Hermann Stamm-Wilbra |
Re: [xsl] Restrictind a set of note, G. Ken Holman | Date | Re: [xsl] how to handle Attributes, Wendell Piez |
Month |