Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 3rd, 2005, 04:25 PM
Registered User
Join Date: Feb 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Section Grouping (XSL Newbie!)

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: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"/>

Any suggestions appreciated!

Reply With Quote
  #2 (permalink)  
Old February 4th, 2005, 04:00 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

I would take a look at:

One thing is taht when you select your categories you use an absolute path that selects all categories, not just the ones under program:
//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)
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 03:08 PM.

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