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
- Subject: Re: [xsl] Maximum number of cells
- From: Wendell Piez <wapiez at mulberrytech dot com>
- Date: Wed, 20 Dec 2000 17:17:13 +0000
- Reply-To: xsl-list at lists dot mulberrytech dot com
Mark,
So far as I know, the only way in XSLT 1.0 is to have a recursive named
template visit each row in turn, saving up the value of the largest as it
goes. Nasty, but it does the job.
For example,
<xsl:template match="/">
<xsl:call-template name="mostCells"/>
</xsl:template>
<xsl:template name="mostCells">
<xsl:param name="rowsToGo" select="//rows"/>
<xsl:param name="mostCellsSoFar" select="0"/>
<xsl:if test="rowsToGo">
<xsl:call-template name="mostCells">
<xsl:with-param name="rowsToGo" select="$rowsToGo[position() > 1]"/>
<xsl:with-param name="mostCellsSoFar">
<xsl:choose>
<xsl:when test="count(cell) > $mostCellsSoFar">
<xsl:value-of select="count(cell)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$mostCellsSoFar"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:value-of select="$mostCellsSoFar"/>
</xsl:template>
(This code is untested, though I've used the algorithm successfully elsewhere.)
It'd be nice to have a neater way. Anyone?
At 04:30 PM 12/20/00 -0500, you wrote:
>Hello,
>
>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). Does anyone
>have any ideas? Any help would be greatly appreciated.
>
>Mark Dudley
>Xerox Corp.
>mark.dudley@usa.xerox.com
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list