Victor
Victor

Reputation: 1159

XSL - Generating list of files from directory on network

I am trying to list directory files with xsl using collection function. It seems to work for normal use case (searching in a local directory), but it fails when searching on a path on the network: eg. \\name_of_machine\the\path\to\folder

The log error is:

FODC0002: The file or directory
  file:/D:/the/current/location/of/the/executing/xsl/%5C%5Cname_of_machine2%5Cthe%5Cpath%5Cto%5Cfolder does not exist

And a snippet from my code:

<xsl:variable name="docList" select="for $f in collection($dir) return lower-case($f)"/>

So, basically, the collection function is prepending the current location of the XSL file that is executing the code and then it escapes all \ (backslash) characters.

How is it possible to use the collection function for retrieving files over network ?

EDIT: I am using Saxon-HE 9.8.0-15

Upvotes: 0

Views: 175

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167696

I think you can use e.g. <xsl:variable name="doc-list" select="uri-collection('file:////name_of_machine/the/path/to/folder?select=*.xml')"/> to get a list of URIs to files in a directory with Saxon 9. I think the URI syntax to represent such a path is file:////name_of_machine/the/path/to/folder.

A test here on a Windows 10 machine using Saxon 9.8 gives

java -cp 'C:\Program Files\Saxonica\Saxon9.8HE\saxon9he.jar' net.sf.saxon.Query -t -qs:"uri-collection('file:////machine-name/Users/marti/SomeFolder/xml?select=*.xml')"
Saxon-HE 9.8.0.15J from Saxonica
Java version 1.8.0_252
Analyzing query from {uri-collection('file:////machine-name/Users/marti/SomeFolder/xml?select=*.xml')}
Analysis time: 194.6869 milliseconds
<?xml version="1.0" encoding="UTF-8"?>file:////machine-name/Users/marti/SomeFolder/xml/sample1.xml file:////machine-name/Us
ers/marti/SomeFolder/xml/sample2.xml

Upvotes: 1

Related Questions