This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Maximum number of cells


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]