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]

max of ... (was your mail)



On Thu, Mar 08 '01 at 12:26, Lindy Quick wrote:
> <profile-table>
>    <row>
>       <whole-request>123</whole-request>
>       <sub-request>23</sub-request>
>       <another-request>100</another-request>
>    </row>
> [ ... ]
> </profile-table>
> 
> I have tried to determine the Whole Request maximum, using xsl:call-template
> to put it in the proper <td> of my table
> 
> <xsl:template name="WholeRequestMax">
>    <xsl:variable name="max">
>      <xsl:for-each select="row/whole-request">
>        <xsl:sort data-type="number" order="descending"/>
>        <xsl:if test="position()=1">
>     <xsl:value-of select="."/></xsl:if>
>      </xsl:for-each>
>    </xsl:variable>
> </xsl:template>
> 
> However, I return no data and my <td> is empty, can anyone tell me what
> I am doing wrong.
You don't produce any output, remove the <xsl:variable> ...
</xsl:variable>, and your template will produce your desired output.

<xsl:template name="WholeRequestMax">
  <xsl:for-each select="row/whole-request">
    <xsl:sort data-type="number" order="descending"/>
    <xsl:if test="position()=1">
      <xsl:value-of select="."/>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

I don't think this i to effective, though. You walk through all nodes
while you only need the first one. But assuming the <xsl:sort> takes 
O(n log(n)) the additional O(n) to test all sorted nodes does not hurt.

I tried to think up something better using another called template bat
failed :-( ... some times later i will have time again to think about how 
to otimize XSL-Ts.

Cu,
    Goetz.

PGP signature


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