RE: Missing functions in XQuery 1.0 and XPath 2.0 Functions and O perators

> I am wondering why the following functions are not included:

Obviously there are hundreds (thousands!) of functions that we could have
included but have not. We have consciously tried to keep the library as
small as possible, and in fact some people complain that it is already much
too large compared with XPath 1.0.
> 
> 1) Equivalents to the Java indexOf() and lastIndexOf() operations on
>     strings.
> 
>     A typical use case of the latter is to extract the last part of a
>     path, e.g. "/this/is/my/path". In this particular case, there is a
>     simple workaround, for example:
> 
>       fn:tokenize("/this/is/my/path", "/")[last()]
> 
>     This is potentially less efficient than a function implementing a
>     dumb lastIndexOf() though, and there are arguably cases where you
>     just need the index in the string rather than a token.

With string handling functions, we have been guided by experience with XPath
1.0. There are a few things that XPath 1.0 users find difficult to achieve,
and we have plugged most of these gaps. In my experience most of the use
cases for indexOf() in Java are so that you can then use substring() to do
the equivalent of XPath's substring-before() and substring-after(). More
complex string processing in XPath 1.0 requires recursive user-written
functions, but from what I can see this will very rarely be needed in XPath
2.0. If you showed a use case for which there isn't a simple workaround,
your case would be more convincing. If the worst comes to the worst, you can
write indexOf yourself using string-to-unicode and unicode-to-string.
> 
> 2) A regexp function that simply returns a sequence of matching
>     groups. I know that XSLT 2.0 provides xsl:analyze-string which
>     provides advanced matching functionality, but given the 
> presence of
>     fn:matches, fn:replace and fn:tokenize in XPath, there is room for
>     such a function in XPath itself.

Can you provide a use case?
> 
> 3) There is fn:escape-uri, but no unescape-uri. Java for example
>     provides an URLDecoder and an URLEncoder.
> 
This has been requested before, but I'm not aware of any context where
unescaped URIs (which are not URIs at all, of course) are needed. Do you
know of such a context?

Michael Kay

Received on Tuesday, 14 October 2003 12:06:43 UTC