Re: [xsl] Grouping

Subject: Re: [xsl] Grouping
From: omprakash.v@xxxxxxxxxxxxx
Date: Wed, 7 Dec 2005 14:37:53 +0530
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: [xsl] 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