Ferran,

in cases like this I use the following idea: put the first specimen of a
group inside a variable and compare it against every new row, if it stays
the same, don't print it, if it changes, print it.

Here's an example (which may not be a good one, since I've cut'n'pasted the
stylesheet I actually use):

<xsl:template match="sql:rowset">

        <xsl:for-each select="sql:row">

                <xsl:variable name="pos"><xsl:value-of
select="position()"/></xsl:variable>
                <xsl:variable name="seccio-prev"><xsl:value-of
select="//sql:row[position()=($pos - 1)]/sql:seccio"/></xsl:variable>

                <xsl:if test="$seccio-prev != sql:seccio">
                        <xsl:value-of select="sql:seccio"/>
                </xsl:if>

                <xsl:value-of select="sql:subseccio"/>

        </xsl:for-each>

</xsl:template>


I hope this helps...

Best regards,

---------------------------------------------
               Luca Morandini
               GIS Consultant
              [EMAIL PROTECTED]
http://utenti.tripod.it/lmorandini/index.html
---------------------------------------------

-----Original Message-----
From: Ferran Urgell [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 19, 2002 4:34 PM
To: [EMAIL PROTECTED]
Subject: Cocoon sql xsl grouping


Hi Cocooners!!
I've a query into a database, and I'm getting the next results:

<?xml version="1.0" encoding="UTF-8" ?>
- <page xmlns:sql="http://apache.org/cocoon/SQL/2.0";>
- <rowset name="lab" xmlns="http://apache.org/cocoon/SQL/2.0";>
- <row>
  <nprg>90E501815</nprg>
  <npet>96139468</npet>
  <fext>19960827</fext>
  <hext>0000</hext>
  <servei>PSIQUIATRIA</servei>
  <origen>PSIQUIATRIA</origen>
  <solic />
  <llit />
- <rowset name="lab1">
- <row>
  <seccio>HEMATOLOGIA</seccio>
- <rowset name="lab2">
- <row>
  <subseccio>HEMATOL. BIOLOGICA - HEMA</subseccio>
  <codi>11100-9</codi>
  <descripcio>VPM</descripcio>
  <resu>11,1</resu>
  <unitat>fl</unitat>
  <vref>(6,0-10,5)</vref>
  </row>
- <row>
  <subseccio>HEMATOL. BIOLOGICA - HEMA</subseccio>
  <codi>11100-10</codi>
  <descripcio>PLAQUETOCRIT</descripcio>
  <resu>0,20</resu>
  <unitat>%</unitat>
  <vref />
  </row>
- <row>
  <subseccio>HEMATOL. BIOLOGICA - HEMA</subseccio>
  <codi>11100-11</codi>
  <descripcio>PDW</descripcio>
  <resu>42</resu>
  <unitat>%</unitat>
  <vref />
  </row>
- <row>
  <subseccio>HEMATOL. BIOLOGICA - HEMA</subseccio>
  <codi>11101-10</codi>
  <descripcio>MONOCITS ABSOLUTS</descripcio>
  <resu>0,57</resu>
  <unitat>x10E9/l</unitat>
  <vref>(<0,80)</vref>
  </row>
  </rowset>
  </row>
  </rowset>
  </row>
  </rowset>
  </page>

And after get this sql-xml I would to get the all the information of the xml
file, I'm trying to group the <codi> <descripcio> <resu> <unitat> <vref>
according to the <subseccio> name... (without duplicates of "subseccio")
I'm trying to do this, with the <xsl:key> .... and generate-id(.) but I'm
getting some problems....

I would to get something like this:

HEMATOLOGIA
-         HEMATOL. BIOLOGICA - HEMA
                  11100-9
                  VPM
                  11,1
                  fl
                  (6,0-10,5)
-
                 1100-10
                  PLAQUETOCRIT
                  0,20
                  %

                  1100-11
                  PDW
                  42
                  %

                   11101-10
                   MONOCITS ABSOLUTS
                   0,57
                   x10E9/l
                  (<0,80)


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

Reply via email to