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: XPath 2.0: Collection-Valued Expressions (Was: Re: XQuery 1.0 and XPath 2.0


> One thing that seems to be missing from the F&O WD is support for
> XPath 2.0 Requirement 2.5 "Should Support Aggregation Functions Over
> Collection-Valued Expressions".
> 
> There are frequently cases where it would be useful to evaluate an
> expression to use for calculating sums, maxima, minima, averages, sort
> values and so on. We currently have to use case-specific templates or
> something along the lines of Dimitre's generic templates to do this
> kind of thing.
> 
> Tied in with this is the oft-requested functionality of being able to
> dynamically evaluate a string as an XPath. Put these together, and an
> expression data type along the lines of the one in Saxon seems like a
> good idea.
> 
> Examples of how I'd like to see it working:
> 
> Work out the total payable on a purchase order:
> 
>   xf:sum(Order/Item, xf:expression('@Price * @Quantity'))
> 
> Find the row with the most cells in it:
>   
>   xf:max(tr, xf:expression('count(td)'))
> 
> Sort a sequence of strings by their length:
> 
>   xf:sort('fubar foo foobar', xf:expression('string-length(.)'))
> 
> Is there a reason that this requirement isn't covered in the F&O
> document?

Because in XSLT 2.0 there will be the so called "stylesheet-functions", it would be
more general and more useful to have a "function-reference data type" as the type of
the second argument of the above xpath functions:

(1)   xf:sum(Order/Item, xf:function($fnRef-multiplier, '@Price', '@Quantity'))

(2)   xf:max(tr, xf:function($fnRef-quantifier, 'td'))
 
(3)   xf:sort('fubar foo foobar', xf:function($fnRef-sort-criterion, '.'))

where any $fnRef variable is a reference to a stylesheet function (Jeni is right
that there is a direct analogy here to the mechanism of generic templates, where a
template reference is used to uniquely identify a template). 
This means that there will be a function that takes an existing stylesheet function
name and produces a function-reference from it:

xf:function-reference(QName)

As I have argued elsewhere, true run-time polymorphism can be implemented based on
template or function references.


The same effect as using xf:function() in (1) - (3) could possibly be achieved by
using:

xs:expression($fnRef(parameter?))

however this might lead to undesirable ambiguities for specifying and using
variables and function references in an expression and would generally make
expressions less readable.

There isn't any such ambiguity in case a dynamic (variable) function reference is
allowed only as the first argument of only one function -- xf:function().

Cheers,
Dimitre Novatchev.



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

 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]