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 July 18th, 2007, 05:33 PM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT - Grouping by Attribute but same elements

Hello,
Here is my XML:
<table>
   <data>
        <form uuid="7eb088d0-e307-4901-aa21-d3cdd7c6823b">
            <field ref="label">Label add Tag1</field>
            <field ref="description">Adding a Task for Tag1</field>
            <field ref="tag">TAG1</field>
        </form>
        <form uuid="8f289097-6164-4398-ba0a-115c4edb5fec">
            <field ref="label">Label added</field>
            <field ref="description">Adding a Task for Tag2</field>
            <field ref="tag">TAG2</field>
           </form>
        <form uuid="54faebbd-c80c-4411-868f-019be6a06198">
            <field ref="label">One more Label</field>
            <field ref="description">Adding a Task for Tag3</field>
            <field ref="tag">TAG3</field>
         </form>
     <form uuid="54faebbd-c80c-4411-868f-019be6a06198">
            <field ref="label">One more Label in Tag 2</field>
            <field ref="description">Adding a Task Tag2</field>
            <field ref="tag">TAG2</field>
         </form>
    </data>
  </table>

My XSL:
    <xsl:key name="filter-by-label" match="table/data/form" use="field[@ref='tag']" />
<xsl:for-each select="table/data/form[generate-id() = generate-id(key('filter-by-label', field[@ref='tag']))]">
                <b><xsl:value-of select="field[@ref='tag']" /></b> <br />
                <xsl:for-each select="key('filter-by-label', field[@ref='tag'])">
                    -- <xsl:value-of select="//@ref='label'"/>
                </xsl:for-each>
            </xsl:for-each>



I would like to Group the Result like this:
 TAG1
    - Adding a Task for Tag1
 TAG2
    - Adding a Task for Tag2
    - One more Label in Tag 2
 TAG3
    - Adding a Task for Tag3

I am not sure how to retrieve the result like shown above.

I really appreciate your help.

Thanks,
Vin
 
Old July 18th, 2007, 06:11 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't understand why your specimen output for TAG2 includes the label field of one of the forms, and the description field of another. Assuming you always want to output the description, use

<xsl:value-of select="field[@ref='description']"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 18th, 2007, 10:34 PM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mr.Kay. Forgive my typo. When I reconstruct it from the original data, I misplaced the data. But looks like this logic is fine but I had to fix outer loop in my original code.

Thanks again,
Vin





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping by attribute aiyer0912 XSLT 1 November 13th, 2006 06:47 AM
Replacing elements name while grouping. ROCXY XSLT 3 January 6th, 2006 01:11 PM
Grouping orphan nodes to paranet elements ROCXY XSLT 2 January 1st, 2006 07:11 AM
elements to attribute value samedan XSLT 0 July 4th, 2005 11:05 AM
Grouping Elements using XSLT mathuranuj XSLT 2 June 21st, 2005 02:56 AM





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