RE: [xsl] Maximum number of cells

Subject: RE: [xsl] Maximum number of cells
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Tue, 2 Jan 2001 11:26:29 -0000
Mark Dudley:
> Given the following XML:
> 
> <table>
>   <row>
>    <cell>...</cell>  
>   </row>
>   <row>
>    <cell>...</cell>
>    <cell>...</cell>
>    <cell>...</cell>
>   </row>
>   <row>
>    <cell>...</cell>
>    <cell>...</cell>
>   </row>
> </table>
> 
> I need to compare the number of cells in each row element and 
> get the count
> of cell elements in the row that has the most (3 in this 
> case). 

there's no built in max and min functions; alternatives are:

(a) sort, and find the first/last
(b) recursive template
(c) extension functions saxon:max(), saxon:min()

Doing (a), with <table> as current node:

<xsl:variable name="maxcells">
  <xsl:for-each select="row"><xsl:sort select="count(cell)"
order="descending"/>
    <xsl:if test="position()=1"><xsl:value-of
select="count(cell)"/></xsl:if>
  </xsl:for-each>
</xsl:variable>

Mike Kay

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


Current Thread