Well, Liam, as I said - it can be done, my request is for supporting elegance.

Here's the litmus test. How would you rewrite this little function ...


declare function f:docs($dir, $fname, $deep) as document-node()* {
    file:list($dir, true(), $fname) ! concat(file:resolve-path($dir), '/', .) ! (try {doc(.)} catch * {})
};

Such a function is a great thing - imagine I want to know the XSLT versions used in a project, so all I have to do is ...

f:docs("foo-project", "*.xsl", $true())/*/@version => distinct-values() => sort()

The goal is to allow the user to be able to specify $dir relative to the current working dir (not the static URI of the query, as doc() expects ...).

To use resolve-uri() is even more cumbersome, because you would require the absolute URI corresponding to $dir, which you can only get by first retrieving the full path of $dir (using file:resolve-path()) and then transforming the full path into a URI, as the result of file:resolve-path() is not accepted by resolve-uri().

So the alternative to this "concat fiddling" would by an even uglier line:

file:list($dir, false(), $fname) ! resolve-uri(., file:path-to-uri(file:resolve-path($dir))) ! doc(.)

Then, *please* let us have this instead:

file:list2($dir, false(), $fname) ! doc(.)

Kind regards,
Hans-Jürgen

Am Freitag, 11. Februar 2022, 20:06:44 MEZ hat Liam R. E. Quin <liam@fromoldbooks.org> Folgendes geschrieben:


On Fri, 2022-02-11 at 18:40 +0000, Hans-Juergen Rennau wrote:
>
> (a) It is the full paths what we need in order to parse the files
> (doc(), json:doc(), csv:doc(), html:doc()).

Why?

A relative path should work fine; if necessary you can use resolve-
uri() to turn a relative path into a full URI.


> (b) The combination of file listing and parsing in a single
> expression is of matchless elegance and expressiveness
>
> Currently, if I don't overlook something, I have to do this:  
> file:list($dir, false(), $fname) ! concat($dir, '/', .) ! doc(.) =>
> count()


Probably, you should use resolve-uri($dir, base-uri(.)) although i
suppose you also need to watch for filenames containing colons...

--
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org