Re: [xsl] Preferred declarative approach for outputting tallies based on complex triggers

Subject: Re: [xsl] Preferred declarative approach for outputting tallies based on complex triggers
From: David Rudel <fwqhgads@xxxxxxxxx>
Date: Thu, 10 Apr 2014 14:20:00 +0200
On Thu, Apr 10, 2014 at 2:00 PM, David Carlisle <davidc@xxxxxxxxx> wrote:

> Well quite I was going to ask what you mean by
> "declarative/non-declarative and "updating state variables" in an XSLT
> system.

Didn't you hear? Michael Kay showed us how to update variables in XSLT
:J (reference to another thread...)

Seriously, I was just referring to using a variable of the same name
in a new scope, as in:
<xsl:next-iteration>
<xsl:param name="var1" select="$new.var1"/>
</xsl:next-iteration>


> I'd do something like something (untested)
>
> <xsl:variable name="sids" select="31,35"/>
> <xsl:variable name="a" select="(item[1],item[@id=$sids][1])[last()]"/>
> <xsl:variable name="b"
> select="(item[last()],item[@id=$sids][last()])[last()]"/>
> <xsl:variable name="s" select="$a|item[$a&lt;&lt;.][.&lt;&lt;$b]|$b"/>
>
> no of items <xsl:value-of select="count($s)"/>
> no of specials <xsl:value-of select="count($s[@id=$sids])/>
> avg  <xsl:value of select="sum($s/@value) div count($s)"/>
>

Thanks, David. I was trying to avoid this approach for performance
considerations. I wanted to do this type of analysis in a single pass.

(Also, I don't think this specific implementation addresses the
possibility that an item with the same @id might show up  multiple
times, and only the first one is "special." So I was expecting this
approach to need something like "for $s in $sids return index-of($s,
$seq/@id)[1]" to retrieve the positions of the special items... this
seemed to me to be quite expensive if there were several such items
and the number of $items is large.

So I was planning on using <xsl:iterate> and keeping track of
information such as:
Have I seen a special item yet? (this is what I mean as a "trigger" as
it signals when to start keeping track of data.)

What $sids have I not seen yet? (This lets me judge whether a given
item is "special" since it is only special the first time.)

What is the sum of all values for @value among items I _know_ to be in
the subsequence I care about.

What is the sum of all values for @value that I have seen since the
last time I saw a special item? (This sum will be added to the above
sum next time I see a special id for the first time.)

And similar information like the above that can then be brought
together at the end to give the results I want in a single pass.

-David

-- 

"A false conclusion, once arrived at and widely accepted is not
dislodged easily, and the less it is understood, the more tenaciously
it is held." - Cantor's Law of Preservation of Ignorance.

Current Thread