[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
Jeni, Thanks so much for your help. But I still can't get my <xsl:for-each select="header | following-sibling::header[position() < 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() < 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() < 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() < 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|