Re: [xsl] Maximum number of cells

Subject: Re: [xsl] Maximum number of cells
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 20 Dec 2000 17:17:13 +0000
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() &gt; 1]"/>
      <xsl:with-param name="mostCellsSoFar">
        <xsl:choose>
          <xsl:when test="count(cell) &gt; $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@xxxxxxxxxxxxx

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

====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx 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



Current Thread