[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: Goetz Bock <bock@xxxxxxxxxxx>
Date: Wed, 20 Dec 2000 23:13:50 +0100
number of cells
Hi Mark,
> 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.

I don't have the time th check this, but the sollution should be
somewhat along the line of:

<template match="table">
  <variable name="max_cols">
    <call-template name="count_cols_per_row">
      <with-param name="row">
        <value-of select="count(row)"/>
      </with-param>  
    </call-template>
  </variable>  
  <!-- do your processing here -->
</template>

<tempalte name="count_cols_per_row">
  <param name="row">0</param>
  <param name="max_cols">0</param>

  <choose>
    <when test="row &gt; 0">
      <variable name="cols">
        <value-of select="count(row[$row]/col)"/>
      </variable>
      <variable name="max">
        <choose>
          <when test="$max_cols %lt; $cols">
            <value-of select="$cols"/>
          </when>
          <otherwise>
            <value-of select="$max_cols"/>
          </otherwise>
        </choose>  
      </variabe> 
      <call-template name="count_cols_per_row">
        <with-param name="row">
          <value-of select="$row - 1"/>
        </with-param>
        <with param name="max_cols">
          <value-of select="$max"/>
        </with-param>
      </call-template>
    </when>
    <otherwise>
      <value-of select="$max_cols"/>
    </otherwise>  
  </choose>
</template>  

This should to the trick, it can for sure be optimized and now has about
O(rows) runtime.

Cu,
    Goetz.

Attachment: pgp00002.pgp
Description: PGP signature

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.