Re: [xsl] Dynamically generating lists of finite length

Subject: Re: [xsl] Dynamically generating lists of finite length
From: Dimtre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sat, 14 Aug 2004 15:10:21 +1000
The following code presents one simple (not necessarily efficient)
compact and straightforward solution ot the splitting of "/a/b/c"
elements into pages of fixed length.

It doesn't address the other aspects of the problem, but these should
not be difficult, too:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 
 <xsl:variable name="vRecsPerPage" select="11"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="/*/b/c">
    <xsl:variable name="vPos">
      <xsl:number count="/*/b/c" level="any"/>
    </xsl:variable>
    
    <xsl:if test="$vPos mod $vRecsPerPage = 1">
      <page number="{ceiling($vPos div $vRecsPerPage)}"/>
    </xsl:if>
    
    <xsl:copy-of select="."/>
  </xsl:template>
</xsl:stylesheet>


Cheers,

Dimitre Novatchev.

On Fri, 13 Aug 2004 15:48:07 -0700, Brendan Moran <bmoran@xxxxxxxxx> wrote:
> Hi,
> I'm using xsl to generate a series of pages dynamically from a
> database.  I want to produce pages with a finite number of records
> (say 100) out of a 3 level tree,
> <a>
>   <b>
>      <c>1</c>
>      <c>2</c>
>      <c>3</c>
>      <c>4</c>
>   </b>
>   <b>
>      <c>1</c>
>      <c>2</c>
>      <c>3</c>
>      <c>4</c>
>      <c>5</c>
>      <c>6</c>
>   </b>
> <!--(etc. etc. etc.)-->
> </a>
> 
> Some attributes of 'b' elements need to be displayed at the start of a
> 'b' section or at the start of a page if a 'b' section is split across
> pages.  Only 'c' elements count towards the 100 elements per page.
> And I need to generate a link to the next page (just <a
> heref="javascript:foo(param1,param2,param3...);">) and the previous
> page.  Preferably at top and bottom.
> 
> The number of c elements in any given b element is unknown, and has no
> practical limit.  There may be b elements that contain no c elements.
> Naturally, information for those b elements should not be displayed.
> 
> I've been trying to figure this one out for a while now, but I'm lost
> on it.
> 
> Thanks
> --
> 
> Brendan Moran
> Research & Development
> http://www.tri-m.com

Current Thread