Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 December 1st, 2004, 05:07 PM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Grouping like data

Hi, I'm *very* new to XSLT, and I am having an issue grouping some nested data.

I have Nodes that all have "Shift" data. Within these Shifts, I have a Part Number. Now, and want to be able to group and add together all the data associated with a Part Number, regardless of what Shift it was produced in.

<shift>
<partNo num="1">
<data count="2"/>
<data time="3"/>
</partNo>
</shift>
<shift>
<partNo num="1">
<data count="1"/>
<data time="5"/>
</partNo>
</shift>
<shift>
<partNo num="2">
<data count="5"/>
<data time="7"/>
</partNo>
</shift>

For example, I want to be able to add together all the "counts" for part number 1. Any ideas on how I should get started would be much appreciated!

Thanks!


Andrew
 
Old December 1st, 2004, 05:48 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

All you ever wanted to know about grouping in XSLT 1.0 is found at

http://www.jenitennison.com/xslt/grouping

It gets much easier in XSLT 2.0!



Michael Kay
http://www.saxonica.com/
 
Old December 2nd, 2004, 07:07 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi andrew

Grouping is the most difficult thing to grasp as a newbie!
Once you have grasped the Muenchen method (on site Michael mentioned) things become clearer...

Try the following:

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

<xsl:key name="partNo" match="partNo" use="@num" />

<xsl:template match="/">
    <xsl:for-each select="foo/shift/partNo[count(. | key('partNo', @num)[1]) = 1]">
        <xsl:sort select="@num" />
        Part num: <xsl:value-of select="@num" />
        <xsl:for-each select="key('partNo', @num)">
            [<xsl:value-of select="data/@count" />,
            <xsl:value-of select="data/@time" />]
        </xsl:for-each>
        <br />

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

Regards
Bryan

 
Old December 2nd, 2004, 10:26 AM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys! I'll give that a try.


Andrew





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Report Help - Grouping Data by Week Ending derekdeben Access 8 January 18th, 2007 11:24 AM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
grouping and pagination sasidhar79 Crystal Reports 1 December 6th, 2005 01:12 PM
Non-recursive Data multi-level grouping jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 30th, 2004 03:42 PM
Consecutive Grouping kilika SQL Server 2000 2 July 8th, 2003 07:02 PM





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