Re: [xsl] What does //distinct-values(...) mean?

Subject: Re: [xsl] What does //distinct-values(...) mean?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 9 Apr 2020 08:19:06 -0000
> The above XPath productions clearly shows that, the following XPath
expression
> //distinct-values(..)
>
> is allowed by the XPath language.

Yes, that's undisputed, just as (say) //name() is allowed and returns a
sequence containing the names of all nodes.
>
> The signature of 'distinct-values(..)' function is specified as following in
the XPath 2.0 F&O spec,
>
> fn:distinct-values($arg as xs:anyAtomicType*) as xs:anyAtomicType*
>
> The above function signature, allows as argument to the function, a sequence
of atomic values or a sequence of nodes.

The argument to the function is irrelevant. The "//" doesn't affect the
arguments to the function. It affects the dynamic context for the function,
but distinct-values() doesn't depend on the context (except to the extent that
its arguments depend on the context).
>
> Although, the expression //distinct-values(..) seems to be allowed by the
XPath spec, its run-time result looks to me ambiguous & should likely be
treated as implementation dependent, since the expression
//distinct-values(..) does not have any valid semantics.

Sorry, but that's wrong. The semantics are crystal-clear, just as the
semantics of //name() are crystal clear. The expression might be useless, and
its effect might be non-intuitive, but it's a principle of orthogonal language
design that you don't disallow things merely because they are useless or
non-intuitive. You can't allow some function calls after "//" because you
think they are useful, and disallow others because you think they aren't.

(Having said that, it was probably a mistake in XPath 2.0 to allow expressions
on the rhs of "/" (or "//") that returned atomic values. It would have been
better to require both operands of "/' to return nodes, and to have introduced
the "!" operator for the more general case. I remember Scott Boag arguing
strongly for that approach at the time. Eventually "!" was introduced anyway,
but by then the messy rules for "/" had already found their way into the
language).

Michael Kay
Saxonica
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

Current Thread