Re: [xsl] Tricky inclusion match

Subject: Re: [xsl] Tricky inclusion match
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Tue, 29 Mar 2005 12:13:13 -0600
> Here is what I have so far, I have a match on "record".  I use a key
> "key_paint" to count my "group a" items and the same key to count my
> "groub b" items.  Group a and group b items are predifined as part of
> the xml source.  So, I achieve a unique count of "group a" and "group
> b" items and now I need to evaluate the total of these two.  In plain
> english:  "count unique items and then sum the count".  (see
> additional comments inline below)

I have this feeling I must be missing part of the problem, but why not
just add the variables (ie $groupa_count + $groupb_count) in the
value-of?  (see below)

If you want the sum for both groupa and groupb and then add those
together can't you simply use sum in a template that similar to the
"count" template you have?

> <xsl:template match="record">
> 
> <xsl:variable name="groupa_count">
> 
> !!comment:  right here, instead of a select I'd like to wrap this in a
> SUM() but not possible... or is it?  Using value-of instead doesn't
> drive my template match and it is impossible to implement the use of a
> mode.
> 
> <xsl:apply-templates
> select="ancestor::recordset/record[field[@fieldname='paint']=$luMD_GroupA][generate-id()=generate-id(key('key_paint',field[@fieldname='paint']))]"
> mode="COUNT"/>
> </xsl:variable>
> <xsl:variable name="groupb_count">
> <xsl:apply-templates
> select="ancestor::recordset/record[field[@fieldname='paint']=$luMD_GroupB][generate-id()=generate-id(key('key_paint',field[@fieldname='paint']))]"
> mode="COUNT"/>
> </xsl:variable>

 <xsl:variable name="total_count">
        <xsl:value-of select="$groupa_count + $groupb_count"/>
 </xsl:variable>

<!-- should probably do something with the variable here, but I'm not
sure what you want...perhaps just have the xsl:value-of
select="$groupa_count + $groub_count"? -->
> 
> </xsl:template>
> 
> <xsl:template match="record" mode="COUNT">
> <xsl:value-of select="number(count(ancestor::recordset/record[field[@fieldname='paint']
> = current()/field[@fieldname='paint']]))"/>
> </xsl:template>

Current Thread