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: calculating the length ??


> I hope You can help me solving my problem.
>
> <LIST>
> <ELEMENT lenght="2"/>
> <ELEMENT lenght="10"/>
> <ELEMENT lenght="4"/>
> </LIST>
>
> I would like to know what the max length is for the elements,

There are three solutions:

1: (with O(n^2) performance) is

element[not(../element/@length > @length)]

2: (with O(n log n) performance):

<xsl:for-each select="element">
<xsl:sort select="@length" data-type="number" order="descending"/>
  <xsl:if test="position()=1"><xsl:value-of select="@length"/></xsl:if>
</xsl:for-each>

3: (with O(n) performance):

write a recursive named template that processes the list of elements, at
each iteration compare the length of the current element with the max of the
rest of the list.

Mike Kay
Software AG


 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]