[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Grouping

Subject: Re: Grouping
From: omprakash.v@xxxxxxxxxxxxx
Date: Wed, 7 Dec 2005 14:37:53 +0530
Re:  Grouping
Hi,
   Please check this xsl.

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Transform">

 <xsl:output method="xml"/>

<xsl:key name="rec" match="row" use="question_id"/>

<xsl:template match="/recordset">

<xsl:for-each select="row">
<xsl:if test="generate-id(.) = generate-id(key('rec', question_id))">
<xsl:text>
</xsl:text>
Answers for question <xsl:value-of select="question_id"/>
</xsl:if>
<xsl:text>
</xsl:text>

<xsl:value-of select="key('rec', question_id)/answer"/>
<xsl:text>
</xsl:text>

</xsl:for-each>

 </xsl:template>


regards,
prakash





                                                                                                                                       
                      Phillip B Oldham                                                                                                 
                      <phillip.oldham@         To:      XSL <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>                                          
                      kilo75.com>              cc:      (bcc: omprakash.v/Polaris)                                                     
                                               Subject:  Grouping                                                                 
                      12/07/2005 02:13                                                                                                 
                      PM                                                                                                               
                      Please respond                                                                                                   
                      to xsl-list                                                                                                      
                                                                                                                                       
                                                                                                                                       




Hi all

I've the following xml doc:

<recordset>
     <row>
        <question_id>1</question_id>
        <answer>blah blah blah...</answer>
     </row>
     <row>
        <question_id>1</question_id>
        <answer>blah blah blah...</answer>
     </row>
     <row>
        <question_id>2</question_id>
        <answer>blah blah blah...</answer>
     </row>
     <row>
        <question_id>2</question_id>
        <answer>blah blah blah...</answer>
     </row>
     ...etc...
</recordset>

I'd like to be able to group the output so I get the following:

Answers to question 1:
     - blah blah blah...
     - blah blah blah...
Answers to question 2:
     - blah blah blah...
     - blah blah blah...
...etc...

There isn't a fixed number of answers to each question, so grouping on a
set of say 10 isn't possible. I've tried using preceeding-sibling, but
can't seem to get anywhere with it.

Any ideas?

Phill





This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.