I've done a Muenchian grouping, but how can I use it to generate summary info?

Discussion in 'XML' started by lennyw@comcast.net, Jun 6, 2006.

  1. Guest

    Hi

    I'm trying to use XSLT to do an xml to xml transformation where the
    output xml contains summary data on the information in the input xml.
    I've succesfully done a Muenchian grouping of the data from the input
    xml file, but I can't see how to operate on the grouped result to
    create and output the desired summary data. If someone could give a
    reference to an example or provide an actual example I'd really
    apprecaite it.

    The actual stylesheet for the gouper is shown below. It groups data for
    each input "row" element by "optionSymbol". Once the data is fully
    grouped, I have data in ascending order of "optionSymbol", with the
    same optionSymbols together. Which is a good first step. And it works.

    But now what I'd like to do is sum the values of certain fields across
    "row" elements, average the values of certain fields across
    "row"elements, etc. but do the operations only on row elements sharing
    the same "optionSymbol" Once these summary values have been
    calculated, I want to output ONE "row" element containg the summary
    data and the optionSymbol text for each disticnt optionSymbol in the
    grouped list. Sort of like what you'd see someone do in a simple
    spreadsheet.

    I simply don't see how to accomplish this.

    The thing that has me most confused is if there exists an accessible
    node list of the grouped data at the start of the inner for loop of the
    Muenchian grouper. And if so, how I get at it. If not, is there an
    accessible node list of the grouped nodes after the inner for loop
    ends? And how to get at it ?

    I apologize if this question seems naive, but I've only been doing XSL
    for a few weeks, and I'm trying to use it to create real production
    code. A tall order (for me at least), but that's what's needed!

    I'm wondering if this is even possible with XSLT.

    Here is the XSLT for my Muenchian grouper (adapted from the OReilly
    book):
    <?xml version="1.0"?>

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:eek:utput method="xml" indent="no"/>

    <xsl:variable name="nl">
    <xsl:text>
    </xsl:text>
    </xsl:variable>

    <!-- Group option symbols -->
    <xsl:key name="optionSymbol" match="tr" use="td[20]"/>

    <xsl:template match="/">
    <xsl:for-each
    select="//tr[generate-id(.)=generate-id(key('optionSymbol',
    td[20])[1])]">
    <xsl:sort select="td[20]"/>
    <!-- Now group each row which matches the current optionSymbol -->
    <!-- This gives us a full group of rows for each option symbol -->
    <xsl:for-each select="key('optionSymbol', td[20])">

    <!--SUMMARY SELECTION/ CALCULATION SHOULD HAPPEN HERE-->


    </xsl:for-each>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>


    Thanks in advance for any help.

    Lenny Wintfeld
     
    , Jun 6, 2006
    #1
    1. Advertising

  2. Joris Gillis Guest

    On Tue, 06 Jun 2006 21:10:41 +0200,
    <> wrote:

    > But now what I'd like to do is sum the values of certain fields across
    > "row" elements, average the values of certain fields across
    > "row"elements, etc. but do the operations only on row elements sharing
    > the same "optionSymbol" Once these summary values have been
    > calculated, I want to output ONE "row" element containg the summary
    > data and the optionSymbol text for each disticnt optionSymbol in the
    > grouped list. Sort of like what you'd see someone do in a simple
    > spreadsheet.


    It sounds like you need something like this:
    <xsl:value-of select="sum(key('optionSymbol', td[20])/td[1]) div
    count(key('optionSymbol', td[20]))"/>
    in stead of that inner <xsl:for-each select="key('optionSymbol',
    td[20])"/> loop ...

    But it would be easier to provide an answer when you gave a sample xml
    input and output...

    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Veni, vidi, wiki (http://www.wikipedia.org)
     
    Joris Gillis, Jun 6, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tristan Miller

    XSL grouping (Muenchian)

    Tristan Miller, Jan 31, 2005, in forum: XML
    Replies:
    2
    Views:
    570
    Philippe Poulard
    Jan 31, 2005
  2. reclusive monkey
    Replies:
    2
    Views:
    1,462
    reclusive monkey
    Aug 10, 2005
  3. Jeffrey
    Replies:
    0
    Views:
    352
    Jeffrey
    Feb 28, 2009
  4. Jeffrey
    Replies:
    0
    Views:
    700
    Jeffrey
    Feb 28, 2009
  5. William Gower

    Can grouping be done with datagrid

    William Gower, Apr 25, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    133
    Scott Mitchell [MVP]
    Apr 25, 2004
Loading...

Share This Page