首页 > 解决方案 > XSL - 从网络上的目录生成文件列表

问题描述

我正在尝试使用collection函数列出具有 xsl 的目录文件。它似乎适用于正常用例(在本地目录中搜索),但在网络上搜索路径时失败:例如。\\name_of_machine\the\path\to\folder

日志错误是:

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

还有我的代码片段:

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

因此,基本上,该collection函数将执行代码的 XSL 文件的当前位置放在前面,然后转义所有 \(反斜杠)字符。

如何使用收集功能通过网络检索文件?

编辑:我正在使用 Saxon-HE 9.8.0-15

标签: xmlxsltsaxon

解决方案


我认为您可以使用例如<xsl:variable name="doc-list" select="uri-collection('file:////name_of_machine/the/path/to/folder?select=*.xml')"/>获取 Saxon 9 目录中文件的 URI 列表。我认为表示此类路径的 URI 语法是file:////name_of_machine/the/path/to/folder.

在使用 Saxon 9.8 的 Windows 10 机器上进行的测试给出了

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

推荐阅读