Re: [xsl] different evaluations on sibling elements ...

Subject: Re: [xsl] different evaluations on sibling elements ...
From: Raimund Kammering <raimund.kammering@xxxxxxx>
Date: Tue, 27 Aug 2013 18:26:19 +0200
Wow I really missed a lot - would have made my live much easier if I would
have started right away using the XSLT 2.0!

Okay I got the concept and the <xsl:for-each-group  group-by=""> seams to be
the key to an easy solution - Thanks!
But unfortunately I still don't get it working! Here are some of my
findings/questions:

There is one misplaced bracket:
>  <xsl:value-of select="current-grouping-key(), ': ',
format-number(sum(current-group()/f:duration-in-hours(.), '0.00'))"/>
should be:
<xsl:value-of select="current-grouping-key(), ': ',
format-number(sum(current-group()/f:duration-in-hours(.)), '0.00')"/>

The following is not working:
>  <xsl:variable name="this" select="dateTime(/isodate, time)"/>
I guess this should be:
<xsl:variable name="this" select="dateTime(entry/isodate, entry/time)"/>

But even though I'm getting an exception saying:

"XPDY0002: Axis step child::element('':entry) cannot be used here: the context
item is undefined"

Okay I also found some discussions concerning functions and undefined context
item. But what I understood from these was just that one must add an parameter
and call the function passing the node to process, but this is exactly as you
(Michael) proposed!?

Raimund Kammering

On 27.08.2013, at 11:52, Michael Kay <mike@xxxxxxxxxxxx> wrote:

> Ignoring all your existing logic, I think the summary can be done something
like this:
>
> <xsl:for-each-group select="//entry" group-by="statistics_category">
>  <xsl:value-of select="current-grouping-key(), ': ',
format-number(sum(current-group()/f:duration-in-hours(.), '0.00'))"/>
> </xsl:for-each-group>
>
> <xsl:function name="f:duration-in-hours" as="xs:double" >
>  <xsl:param name="entry" as="element(entry)"/>
>  <!-- TODO: add logic for the case where there's no following-siblng -->
>  <xsl:variable name="this" select="dateTime(/isodate, time)"/>
>  <xsl:variable name="next"
select="dateTime(following-sibling::entry/isodate,
following-sibling::entry/time)"/>
>  <xsl:sequence select="($next - $this) div xs:duration('PT1H')"/>
> </xsl:function>
>
> Michael Kay
> Saxonica

Current Thread