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

Re: FO/XSL:Setting up columns in a for-each loop

Subject: Re: FO/XSL:Setting up columns in a for-each loop
From: Rachael Blank <blankrr@xxxxxxxxxxxxxxxx>
Date: Thu, 01 Nov 2001 12:21:56 -0500
echocardiogram report template
Jeni,

Thanks so much for your help.  But I still can't get my
<xsl:for-each select="header | following-sibling::header[position() &lt;
2]">
to display anything, even without FO.  We are using the SAXON parser.

Our application has a stylesheet for each document type.  In this case,
the document type is an ECHOCARDIOGRAM report.

The section of the XML that I want to display is as follows:
<section>
   <report>
      <datatypeid></datatypeid>
      <header></header>
      <comment></comment>
   </report>
  <report>
      <datatypeid></datatypeid>
      <header></header>
      <comment></comment>
   </report>
    ....
</section>

I want to display in this fashion:
<table>
   <tr>
      <td>header</td>
      <td>comment</td>
      <td>header</td>
      <td>comment</td>
   </tr>
   <tr>
      <td>header</td>
      <td>comment</td>
      <td>header</td>
      <td>comment</td>
   </tr>
</table>

Looks like:
Column1               Column2
Aortic Root: 34     LV Diastole: 3
AO Opening: 3     Systole: 3

Headers are Aortic root, AO Opening, LV Diastole, Systole
Comments are 34,3,3,3

  <table>
      <xsl:for-each select="header[position() mod 2 = 1]">
        <tr>
          <xsl:for-each
              select="header | following-sibling::header[position() &lt;
2]">
            <td>
              <xsl:value-of select="." />
            </td>
          </xsl:for-each>
        </tr>
      </xsl:for-each>
</table>

Any help would be kindly appreciated.

I can send the entire xsl file, if needed.

Thanks again!

Rachael


Jeni Tennison wrote:

> Hi Rachael,
>
> > Thanks so much for the response. Do you happen to know where I can
> > find any FO examples of this type of logic. I am trying this example
> > and others, but I keep getting errors. I think my placements are
> > wrong.
>
> Here's an example. The source is as follows:
>
> <list>
>   <item>item1</item>
>   <item>item2</item>
>   ...
>   <item>item3</item>
> </list>
>
> And you want to create a four-column table. The list equates to an
> fo:table:
>
> <xsl:template match="list">
>   <fo:table>
>     <fo:table-body>
>       ...
>     </fo:table-body>
>   </fo:table>
> </xsl:template>
>
> Now, you want to generate a row for every fourth item in the list. You
> can get every fourth item by seeing if its position mod 4 is equal to
> 1 with:
>
>   position() mod 4 = 1
>
> You can iterate over every fourth item with an xsl:for-each (or you
> can apply templates to them) as follows:
>
> <xsl:template match="list">
>   <fo:table>
>     <fo:table-body>
>       <xsl:for-each select="item[position() mod 4 = 1]">
>         <fo:table-row>
>           ...
>         </fo:table-row>
>       </xsl:for-each>
>     </fo:table-body>
>   </fo:table>
> </xsl:template>
>
> Now you need to create a cell for the current item and its three
> following siblings. You can get the current item with . and its three
> following siblings with:
>
>   following-sibling::item[position() &lt; 4]
>
> And you can iterate over these with xsl:for-each again (or
> xsl:apply-templates if you prefer):
>
> <xsl:template match="list">
>   <fo:table>
>     <fo:table-body>
>       <xsl:for-each select="item[position() mod 4 = 1]">
>         <fo:table-row>
>           <xsl:for-each
>               select=". | following-sibling::item[position() &lt; 4]">
>             <fo:table-cell>
>               <xsl:value-of select="." />
>             </fo:table-cell>
>           </xsl:for-each>
>         </fo:table-row>
>       </xsl:for-each>
>     </fo:table-body>
>   </fo:table>
> </xsl:template>
>
> If that example doesn't help, you could always send the part of the
> stylesheet that's causing problems and we can see if we can spot where
> it should be changed.
>
> I hope that helps anyway,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.com/
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.