Saxon 9.8:EXPath 文件模块函数 file:list 支持哪些模式?

Saxon 9.8: Which patterns are supported in EXPath File Module function file:list?

下午好,

我正在使用 Java Saxon 9.8.0.4。我想使用 EXPath 文件模块函数 "file:list" 及其第三个 "pattern" 参数。但是我有疑问,支持哪种样式的模式。

我都读了Saxon documentation and EXPath documentation. But I do not know, which patterns are supported in Saxon 9.8.0.4. It would be great to support regular expression, but I understand it is overkill for most users. I tried several blind tests, but just * and ? wildchars works for me as defined in EXPath documentation

是的,我可以很容易地在 for-each 中进行正则表达式后处理,但了解更多有关列表函数的信息可能会有所帮助。

预先感谢您的帮助,Stepan

P.S:我的用例是从大而深的目录结构中递归地获取所有没有扩展名的文件("test" 而不是 "test.txt")并处理所有匹配的文件XSL-T 3.0。大多数此类文件具有相同的文件名,因此我无法对 Saxon 的 -s:directory -o:directory 进行一次 "copy to one folder" 预处理,并且每个文件的 Java (Saxon) 调用是course 可怕的时间开销。所以我想按顺序读取所有匹配的文件,并使用 for-each 处理此类序列的每个项目(文件是文本文件,我使用未解析的文本读取它们)。不,GAWK 不是解决方案,因为我已经在 XSL-T 中拥有从 XML 到 SQL 的所有转换基础结构,因为 95% 的文件是 XMLs。

--添加代码和下面的解释:

我的测试文件示例。

XML 文件 "a.xml":

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="a.xsl"?>
<root/>

XSL-T 文件 "a.xsl":

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:expathFile="http://expath.org/ns/file"
  exclude-result-prefixes="xs saxon"
  version="3.0">
  <xsl:output method="text" />
  <xsl:template match="/root">
    <xsl:variable name="list" select="expathFile:list('C:\temp\temp\test\', false(), '^.*$')"/>
    <xsl:for-each select="$list">
      <xsl:value-of select="."/>
    </xsl:for-each>
  </xsl:template>

我的文件夹 "C:\temp\temp\test\" 包含 6 个测试文件:"a.txt"、"b.txt"、"c.txt"、"e"、"f"、"g".

但是在“http://www.regexplanet.com/advanced/java/index.html”上对在线 Java RegExp 测试器进行测试后,我发现问题完全出在我这边,因为 Java 正则表达式的行为与PCRE (Perl)、sed、gawk 正则表达式。所以这是我的错,我需要学习 Java 正则表达式。

Saxon 对此模式使用与集合 URI 中 select="pattern" 中过滤器相同的代码,在 http://www.saxonica.com/documentation/index.html#!sourcedocs/collections

中进行了描述

提取相关细节:

The pattern used in the select parameter can use glob-like syntax, for example *.xml selects all files with extension "xml". More generally, the pattern is converted to a regular expression by prepending "^", appending "$", replacing "." by "\.", "*" by ".*", and "?" by ".?", and it is then used to match the file names appearing in the directory using the Java regular expression rules. So, for example, you can write ?select=*.(xml|xhtml) to match files with either of these two file extensions. Note however, that special characters used in the URL (that is, characters such as backslash and curly braces that are not allowed in the query part of a URI) must be escaped using the %HH convention. For example, vertical bar needs to be written as %7C. This escaping can be achieved using the encode-for-uri() function.

请注意,Saxon 的 collection() 函数现在也支持 URI 中的 match=pattern,其中模式是标准的 XPath 3.1 正则表达式。