xsl-list
[Top] [All Lists]

RE: Grouping elements in table using xsl:fo

2004-06-16 09:46:37
At 2004-06-15 14:55 +0100, James Steven wrote:
The main aspect I am having trouble with is getting each unique <B> on a
separate row in the table with each <z> grouped under the relevant <B>.  I
can only get each <B> on the same row and so cannot group under these.

Below is a working version using the Muenchian Method, just change the HTML table constructs to XSL-FO. You'll see the structure as you requested:

At 2004-06-15 12:15 +0100, James Steven wrote:
I would like to create a row for each <z> in a table grouped by the value of
<B>.  For each different value of <B> there would be a heading and on the
rows below each heading each <z> which has the same <B> value.

eg.

                                A   C   D   E
                   gg1
                                ff  hh  ii  jj
                                pp  qq  rr  ss
                        gg2
                                kk  ll  mm  nn
                                ff  hh  ii  jj
                        gg3
                        tt  uu  vv  ww

I hope this helps.

............................. Ken


T:\ftemp>type james.xml
<x>
        <y>
                <z>
                        <A>ff</A>
                        <B>gg1</B>
                        <C>hh</C>
                        <D>ii</D>
                        <E>jj</E>
                </z>
        </y>
        <y>
                <z>
                        <A>kk</A>
                        <B>gg2</B>
                        <C>ll</C>
                        <D>mm</D>
                        <E>nn</E>
                </z>
        </y>
        <y>
                <z>
                        <A>tt</A>
                        <B>gg3</B>
                        <C>uu</C>
                        <D>vv</D>
                        <E>ww</E>
                </z>
        </y>
        <y>
                <z>
                        <A>pp</A>
                        <B>gg1</B>
                        <C>qq</C>
                        <D>rr</D>
                        <E>ss</E>
                </z>
        </y>
        <y>
                <z>
                        <A>ff</A>
                        <B>gg2</B>
                        <C>hh</C>
                        <D>ii</D>
                        <E>jj</E>
                </z>
        </y>
</x>

T:\ftemp>type james.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:output indent="yes"/>

<xsl:key name="entries" match="z" use="B"/>

<xsl:template match="/">
  <table border="1">
    <tr>
      <td></td><td>A</td><td>C</td><td>D</td><td>E</td>
    </tr>
    <xsl:for-each select="/x/y/z[generate-id(.)=
                                 generate-id(key('entries',B))]">
      <tr><td><xsl:value-of select="B"/></td></tr>
      <xsl:for-each select="key('entries',B)">
        <tr>
          <td></td>
          <td><xsl:value-of select="A"/></td>
          <td><xsl:value-of select="C"/></td>
          <td><xsl:value-of select="D"/></td>
          <td><xsl:value-of select="E"/></td>
        </tr>
      </xsl:for-each>
    </xsl:for-each>
  </table>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>saxon -o james.htm james.xml james.xsl

T:\ftemp>type james.htm
<?xml version="1.0" encoding="utf-8"?>
<table border="1">
   <tr>
      <td/>
      <td>A</td>
      <td>C</td>
      <td>D</td>
      <td>E</td>
   </tr>
   <tr>
      <td>gg1</td>
   </tr>
   <tr>
      <td/>
      <td>ff</td>
      <td>hh</td>
      <td>ii</td>
      <td>jj</td>
   </tr>
   <tr>
      <td/>
      <td>pp</td>
      <td>qq</td>
      <td>rr</td>
      <td>ss</td>
   </tr>
   <tr>
      <td>gg2</td>
   </tr>
   <tr>
      <td/>
      <td>kk</td>
      <td>ll</td>
      <td>mm</td>
      <td>nn</td>
   </tr>
   <tr>
      <td/>
      <td>ff</td>
      <td>hh</td>
      <td>ii</td>
      <td>jj</td>
   </tr>
   <tr>
      <td>gg3</td>
   </tr>
   <tr>
      <td/>
      <td>tt</td>
      <td>uu</td>
      <td>vv</td>
      <td>ww</td>
   </tr>
</table>



--
Public training 3 days XSLT & 2 days XSL-FO: Phoenix,AZ 2004-08-23
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



<Prev in Thread] Current Thread [Next in Thread>