[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Hi Ken,
Although you subtlety pointed out my context was Session and not Date (as it should have been), I shortly realized my mistake and altered your suggestion (where you gave me what I asked for) from:
<xsl:value-of select="sum( (. | ../preceding-sibling::Date/Session)/Notes/@hours-worked)"/>
to (what I should have asked you for):
<xsl:value-of select="format-number(sum((Session | preceding-sibling::Date/Session)/Notes/@hours-worked), '.00')"/>
and, of course, changed its context to Date.
Works much better.
-----Original Message----- From: G. Ken Holman
Sent: Friday, April 13, 2012 1:20 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx ; xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Summing hours-worked values from previous siblings only
to determine accrued hours
At 2012-04-13 13:16 -0700, Mark wrote:
In XSLT 2.0:
I hope this helps.
. . . . . . Ken
Re: [xsl] Summing hours-worked values from previous siblings only to determine accrued hours
Subject: Re: [xsl] Summing hours-worked values from previous siblings only to determine accrued hours From: "Mark" <mark@xxxxxxxxxxxx> Date: Sat, 14 Apr 2012 12:47:48 -0700 |
Hi Ken,
Although you subtlety pointed out my context was Session and not Date (as it should have been), I shortly realized my mistake and altered your suggestion (where you gave me what I asked for) from:
<xsl:value-of select="sum( (. | ../preceding-sibling::Date/Session)/Notes/@hours-worked)"/>
to (what I should have asked you for):
<xsl:value-of select="format-number(sum((Session | preceding-sibling::Date/Session)/Notes/@hours-worked), '.00')"/>
and, of course, changed its context to Date.
Works much better.
Thanks again for all your help, Mark
-----Original Message----- From: G. Ken Holman
Sent: Friday, April 13, 2012 1:20 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx ; xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Summing hours-worked values from previous siblings only
to determine accrued hours
At 2012-04-13 13:16 -0700, Mark wrote:
I am creating a work-report sheet that needs to know the value of working hours accrued to the current date for each date. The xml looks like this
<Month name=C"b,BAprilC"b,B>
<Date day="1">
<Session task="LS Authorities">
<Notes hours-worked="2.00" notes="Documented changes from last week."/>
</Session>
</Date>
<Date day="2">
<Session task="LS Authorities">
<Notes hours-worked="2.00" notes="Worked with Wayne resolving $2 border cases (see Campfire notes)."/>
<Notes hours-worked="1.50" notes="Final boarder case resolution and 655/150 issue."/>
</Session>
</Date>
</Month>
I can get a Daily total of hours worked with a named template called from the Sessions template, but how can I show the hours accrued for all previous days?
For the XLM given, My output for the first Date should be C"b,EDaily Total: 2.0 Accrued: 2.0.C"b,B
and for the second Date C"b,EDaily Total: 3.5. Accrued: 5.5.C"b,B
That is, I need to know the value of all *previous* hours-worked and exclude any *following* hours-worked. The XSLT so far look like this:
<xsl:template match="Session"> <fo:table-row> <fo:table-cell> <fo:block xsl:use-attribute-sets="subdiv1"> <xsl:value-of select="@task"/> </fo:block> </fo:table-cell> </fo:table-row> <xsl:apply-templates/> <xsl:call-template name="day-total"/> </xsl:template>
<xsl:template name="day-total"> <fo:table-row> <fo:table-cell> <fo:block xsl:use-attribute-sets="subdiv3"> <fo:wrapper xsl:use-attribute-sets="title"> <xsl:text>Daily Total: </xsl:text> </fo:wrapper> <xsl:value-of select="sum(Notes/@hours-worked)"/> <fo:wrapper xsl:use-attribute-sets="title"> <xsl:text>Accrued: </xsl:text> </fo:wrapper> <!-- What goes here to select all previous Notes/@hours-worked??? <xsl:value-of select="sum(?????????????Notes/@hours-worked)"/>
Since your current node is <Session> you need to address the Notes descendant of all preceding siblings of the parent Date, plus the Notes child of the current node:
<xsl:value-of select="sum( (. | ../preceding-sibling::Date/Session)/Notes/@hours-worked)"/>
Note that if any of the attribute values might possibly be the empty string, your sum() will be affected and you can protect the sum in XSLT 1.0 by using a predicate:
<xsl:value-of select="sum( (. | ../preceding-sibling::Date/Session)/Notes/@hours-worked[number()=number()])"/>
In XSLT 2.0:
<xsl:value-of select="sum( (. | ../preceding-sibling::Date/Session)/Notes/@hours-worked[. castable as xsd:double])"/>
</fo:block> </fo:table-cell> </fo:table-row> </xsl:template>
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Summing hours-worked valu, Mark | Thread | [xsl] how with xPath 1, Leo Studer |
Re: [xsl] how with xPath 1, G. Ken Holman | Date | Re: [xsl] how with xPath 1, Leo Studer |
Month |