[xsl] Re: Re: xpath for getting file version

Subject: [xsl] Re: Re: xpath for getting file version
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 15 Aug 2001 06:22:33 -0700 (PDT)
Jeni Tennison wrote:

[snip]
> 
> When it comes down to it, this is a problem of finding a calculated
> maximum within an XPath. I think you have at least four options.

> First, you could index the files by all their versions and worry about
> which is latest later on. So use the key:
> 
> <xsl:key name="file-version" match="file" use="versions/version" />
> 
> and then when you're processing the files that you retrieve using the
> key, filter out those that have been retrieved through an early
> version.

> Second, you could have a two-stage process (either with two
> stylesheets or using a node-set() extension function to do it all in
> one stylesheet). In the first pass, construct XML like the above, with
> a date attribute giving the entire date, and then use the XPath above
> in the key.

> Third, you could use an extension function for finding nodes with
> the highest values based on an expression, if your processor offers
> one. If you use Saxon, you could do:
> 
> <xsl:key name="file-version" match="file"
>          use="saxon:highest(versions/version,
>                             saxon:expression('concat(@year, @month,
>                                              @day)'))" />
> 
> Finally, you could write your own extension function to find the latest
> version of a file. With the EXSLT mechanism, it could look like:
> 
> <func:function name="my:latest-version">
>   <xsl:for-each select="versions/version">
>     <xsl:sort select="concat(@year, @month, @day)"
>               data-type="number" order="descending" />
>     <xsl:if test="position() = 1">
>       <func:result select="@name" />
>     </xsl:if>
>   </xsl:for-each>
> </func:function>
> 
> (or you could write a recursive function if speed was an issue)
> 
> In a processor that supports EXSLT - Functions (Saxon or 4XSLT), you
> could do:
> 
> <xsl:key name="file-version" match="file" use="my:latest-version()" />
> 
> I hope that helps,
> 
> Jeni

It would help much more to know that there is another way of finding any maximum.
This, as Jeni knows well, is to use a generic template.

Contrasted to half of the solutions above, the generic max() template, which can be
downloaded at 
http://vbxml.com/downloads/default.asp?id=v2001611171627  
is 100% pure XSLT and does not require the stylesheet programmer to be bound to use
a particular XSLT processor or to write any extension functions, which again will
make the stylesheet non-portable.

The current state of EXSLT as I see it, just clearly proves the need to have a good
100% pure XSLT template library. Ideally we could have a standard XSLT template
library developed by the W3 consortium (as contrasted by any initiative of small and
not quite representative group of people).

Hope this helped.

Cheers,
Dimitre Novatchev.

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



--------------------------------------------------------------------------------

References: 
xpath for getting file version 
From: Antony Suryadinata
Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]  
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next] 


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread