[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Maximum number of cells

Subject: Re: Maximum number of cells
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 20 Dec 2000 17:17:13 +0000
Re:  Maximum number of cells
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.