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 February 3rd, 2005, 04:25 PM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Section Grouping (XSL Newbie!)

Hello!
I am trying to 'run a transform', I think the lingo is, and am coming up against a problem.
I want to display a list of programs, and the categories below each of those programs.
The XML file that I am pulling all the data from has LOTS of lines of the same program, and lots of lines of the same category underneath each program.

The problem I am running up against (when attempting to display unique values) is that there are categories with the same name under different programs. What happens when I run my transform is that those 'duplicate' categories aren't shown.

For example, I want:

Program 1
   AAA Cat
   BBB Cat
Program 2
   CCC Cat
Program 3
   AAA Cat
   DDD Cat

and instead, I get:

Program 1
   AAA Cat
   BBB Cat
Program 2
   CCC Cat
Program 3
   DDD Cat

(the second AAA is removed)

My xsl looks like:


            <xsl:variable name="programs" select="//PROGRAM[not(.=preceding::PROGRAM)]"/>
            <xsl:for-each select="$programs">
                <xsl:variable name="program" select="."/>

                <xsl:element name="section">
                <xsl:element name="title">
                        <xsl:value-of select="$program"/>
                </xsl:element>


                <xsl:variable name="categories"
                        select="//CATEGORY[not(.=preceding::CATEGORY) and preceding-sibling::PROGRAM = $program]"/>
                    <xsl:for-each select="$categories">
                        <xsl:variable name="category" select="."/>
                        <xsl:element name="section">
                            <xsl:element name="title">
                                <xsl:value-of select="$category"/>
                            </xsl:element>
                        </xsl:element>
                    </xsl:for-each>
                </xsl:element>

Any suggestions appreciated!

Thanks,
G.
 
Old February 4th, 2005, 04:00 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I would take a look at:
http://www.jenitennison.com/xslt/gro...muenchian.html

One thing is taht when you select your categories you use an absolute path that selects all categories, not just the ones under program:
Code:
//CATEGORY[not(.=preceding::CATEGORY) and preceding-sibling::PROGRAM = $program]
Your path starts with a / so begins its search at the document root. As you don't show your xml I can't suggest the correct path.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie - grouping from different areas? wilgartw XSLT 5 October 30th, 2007 09:46 AM
xsl grouping aiyer0912 XSLT 9 November 7th, 2006 12:13 PM
cdata-section-elements in xsl:output ROCXY XSLT 1 March 2nd, 2006 11:44 AM
1:M sorting or grouping cant explain :: newbie Q auser99 XSLT 4 April 29th, 2005 11:57 AM
Crystal Reports Section Problem while Grouping softrajesh BOOK: Professional Crystal Reports for VS.NET 0 November 25th, 2004 12:54 AM





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