RE: [newbie]use of xsl:if {RE: XSL to handle display mutiple page s}

Subject: RE: [newbie]use of xsl:if {RE: XSL to handle display mutiple page s}
From: "Xu, Xiaocun" <XXu@xxxxxxxxxxxxxxxxxx>
Date: Fri, 3 Nov 2000 14:45:34 -0400 (EST)
Hi, Mike:

	Thanks for the pointer.  I really need to check the FAQ more
carefully.  I was fixated on "page", and did not thinking of it as a more
generic "element", so I missed out on that in the FAQ.
	Yep, you are right, the <tableheader> should be a call-template.
Reading the FAQ, your and Jeni's explanations, I started to get a much
better understanding how all these fit together.  Much appreciated for all
the guidence :)

Xiaocun Xu
xxu@xxxxxxxxxxxxxxxxxx

> -----Original Message-----
> From: Mike Brown [mailto:mike@xxxxxxxx]
> Sent: Thursday, November 02, 2000 11:56 PM
> To: xsl-list@xxxxxxxxxxxxxxxx
> Cc: XXu@xxxxxxxxxxxxxxxxxx
> Subject: Re: [newbie]use of xsl:if {RE: XSL to handle display mutiple
> pages}
> 
> 
> Xu, Xiaocun wrote:
> >   I started working on XSL to handle display mutiple pages 
> in HTML.  The
> > idea I tried was simple, count number of records until max 
> records per page
> > reaches.  At that time, I close of the current page/table, 
> add a page break
> > and start the next page/table.  But such logic seems does 
> not seems to be
> > allowed in xsl blocks such as xsl:if.  What can be done to 
> get around this
> > problem?
> >   Following is the XSL code I currently have problem with:
> > 
> > <xsl:for-each select="//item">  
> > <tr><!--Display item record here--></tr>
> > <xsl:param name="ItemCount" select="$ItemCount+1"/>
> > <xsl:if test="$ItemCount=$maxItemsPage">
> > 	<!-- end this table and page -->
> > 	</tbody>
> > 	</table>
> > 	<!-- add page break at end of page -->
> > 	<div style='page-break-before: always'> </div>
> > 	<!-- start the next page with new table -->
> > 	<table width="100%" border="1" cellspacing="0">
> > 	<xsl:apply-templates select="tableheader"/>
> > 	<tbody>
> > </xsl:if>
> > </xsl:for-each>
> 
> 
> See the FAQ in the 'Tables' section. #3.
> 
> Note that //item will be inefficient; you might do better to select
> /path/from/root/to/all/item.
> 
> I also assume you really wanted to do a call-template for a 
> named template
> named 'tableheader'... unless you have 'tableheader' elements 
> in your XML?
> 
> <xsl:variable name="maxItemsPage" select="50"/>
> <xsl:variable name="items" select="//item"/>
> <!-- start a new table for item 1, 51, 101, 151, etc. -->
> <xsl:for-each select="$items[(position()+1) mod $maxItemsPage 
> + 1 = 1]"
>   <table width="100%" border="1" cellspacing="0">
>     <xsl:call-template name="tableheader"/>
>     <tbody>
>       <!-- start a new row for current item and the next 49 -->
>       <xsl:variable name="currentPos" select="position()"/>
>       <xsl:for-each select="$items[position() &gt;= 
> $currentPos and position() &lt; $currentPos + $maxItemsPage -1]">
>         <tr>
>           <td>
>             <xsl:value-of select="."/> <!-- or whatever -->
>           </td>
>         </tr>
>       </xsl:for-each>
>     </tbody>
>   </table>
>   <!-- output separator if we're not on the last item in the set -->
>   <xsl:if test="$currentPos + $maxItemsPage &gt; count($items)">
>     <div style='page-break-before: always'/>
>   </xsl:if>
> </xsl:for-each>
> 
> 
>    - Mike
> ____________________________________________________________________
> Mike J. Brown, software engineer at         My XML/XSL resources:
> webb.net in Denver, Colorado, USA           http://www.skew.org/xml/
> 




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


Current Thread