Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2006, 10:07 AM
Registered User
 
Join Date: Mar 2006
Location: , PA, .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default unique grouping-subtotaling problem

I'm trying to get a count for each unique element and a subtotal for an attribute("s"). The total count of each unique element is working fine, however, the summarization of the attribute is not. It seems to just take one instance of the attribute value rather than summing all of them up within the element group.
Here is the XML
<USAGE-LOG-2.0>
    <SEARCH>
          <T s="3"/>
    </SEARCH>
    <VW_COVER>
          <T s="2"/>
    </VW_COVER>
    <VW_COVER>
          <T s="5"/>
    </VW_COVER>
    <VW_COVER>
          <T s="5"/>
    </VW_COVER>
    <VW_COVER>
          <T s="7"/>
    </VW_COVER>
    <VW_COVER>
          <T s="3"/>
    </VW_COVER>
    <REFRESH_WDOC>
          <T s="4"/>
    </REFRESH_WDOC>
    <CR_WDOC>
          <T s="9"/>
    </CR_WDOC>
    <CR_WDOC>
          <T s="7"/>
    </CR_WDOC>
    <RUN_SCRIPT>
          <T s="8"/>
    </RUN_SCRIPT>
</USAGE-LOG-2.0>

Here is the xsl

<xsl:output method="html" />

<xsl:key name="gis" match="USAGE-LOG-2.0/*" use="name()"/> <xsl:template match="node()"> <table>
    <xsl:for-each
select="//*[generate-id(.)=3Dgenerate-id(key('gis',name(.))[1])]">
    <xsl:sort select="name()"/>
<tr><td>
        <xsl:value-of select="name(.)" /></td><td><xsl:value-of select="count(key('gis', name(.)))" /> </td><td>
        <xsl:variable name="responsetime">
             <xsl:for-each select="T">
                  <accum>
                       <xsl:value-of select="@s"/>
                  </accum>
             </xsl:for-each>
        </xsl:variable>
    <xsl:value-of select="sum(msxsl:node-set($responsetime)/accum)"/>
</td></tr>
    </xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

Here is what it returns:

CR_WDOC 2 9
REFRESH_WDOC 1 4
RUN_SCRIPT 1 8
SEARCH 1 3
VW_COVER 5 2

Here is what I expected to get:
CR_WDOC 2 16
REFRESH_WDOC 1 4
RUN_SCRIPT 1 8
SEARCH 1 3
VW_COVER 5 22


 
Old March 31st, 2006, 11:13 AM
Registered User
 
Join Date: Mar 2006
Location: , PA, .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did some searching around the forums and looks like I was able to figure it out. Had to make some adjustments to $response tree fragment. Also, had to adjust how I think about XSL processing, a bit different from my traditional programming background.

<xsl:variable name="response">
    <xsl:for-each select="key('gis',name())">
            <accum>
            <xsl:value-of select="sum(T/@s)"/>
            </accum>
    </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="sum(msxsl:node-set($response)/accum)"/>





Similar Threads
Thread Thread Starter Forum Replies Last Post
DataSet Column with Unique Constrain Problem niceFEPF C# 5 July 31st, 2009 07:04 PM
VS 2005 Problem: project requires a unique name. EugenX Visual Studio 2005 1 September 7th, 2006 09:15 AM
Unique Problem rekha_jsr Classic ASP Basics 0 December 10th, 2005 12:21 AM
Unique Update Problem rekha_jsr Classic ASP Databases 0 December 9th, 2005 02:22 AM
Grouping problem aware Access 11 August 4th, 2005 11:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.