This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Maximum number of cells
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Maximum number of cells
- From: Kay Michael <Michael dot Kay at icl dot com>
- Date: Tue, 2 Jan 2001 11:26:29 -0000
- Reply-To: xsl-list at lists dot mulberrytech dot com
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