xslt 2.0:通过 collection() 读取文本文件
xslt 2.0: read in text files via collection()
我有一堆文本文件要用 XSLT 2.0 处理。
以下是我尝试阅读它们的方式:
<xsl:variable name="input" select="collection(iri-to-uri('file:///.?select=*.txt'))" />
但是,当我这样做时:
<xsl:message>
<xsl:sequence select="count($input)"/>
</xsl:message>
输出0,没有选择文件。
如果我这样做:
<xsl:variable name="input" select="collection(iri-to-uri('.?select=*.txt'))" />
我得到的错误是集合应该 return 一个 node
但是 return 一个 xs:string
.
我想做的是读取每个文件,然后遍历每个文件并处理文本,就像这样
<xsl:for-each select="unparsed-text($input, 'UTF-8')">
<!-- tokenizing, etc. -->
我该怎么做?
您需要 Saxon 9.7(包括 HE 在内的所有版本)和 9.6(我认为是商业版本)的 version="3.0"
样式表中支持的 XPath 3.0 uri-collection
函数:
<xsl:template match="/" name="main">
<xsl:for-each select="uri-collection('.?select=*.txt')!unparsed-text(.)">
<xsl:message select="'Parsed:' || . || ' '"/>
</xsl:for-each>
</xsl:template>
collection
应该是 return 一系列节点,而 uri-collection
可以访问其他无法解析为 XML.
的资源
使用 Altova XMLSpy 分别是 RaptorXML 和 XSLT 3.0 你也可以使用 uri-collection
,似乎访问所有 .txt
文件的方式有点不同来自 Saxon,您使用 uri-collection('*.txt')
访问目录中的所有 .txt
文件。
我有一堆文本文件要用 XSLT 2.0 处理。
以下是我尝试阅读它们的方式:
<xsl:variable name="input" select="collection(iri-to-uri('file:///.?select=*.txt'))" />
但是,当我这样做时:
<xsl:message>
<xsl:sequence select="count($input)"/>
</xsl:message>
输出0,没有选择文件。
如果我这样做:
<xsl:variable name="input" select="collection(iri-to-uri('.?select=*.txt'))" />
我得到的错误是集合应该 return 一个 node
但是 return 一个 xs:string
.
我想做的是读取每个文件,然后遍历每个文件并处理文本,就像这样
<xsl:for-each select="unparsed-text($input, 'UTF-8')">
<!-- tokenizing, etc. -->
我该怎么做?
您需要 Saxon 9.7(包括 HE 在内的所有版本)和 9.6(我认为是商业版本)的 version="3.0"
样式表中支持的 XPath 3.0 uri-collection
函数:
<xsl:template match="/" name="main">
<xsl:for-each select="uri-collection('.?select=*.txt')!unparsed-text(.)">
<xsl:message select="'Parsed:' || . || ' '"/>
</xsl:for-each>
</xsl:template>
collection
应该是 return 一系列节点,而 uri-collection
可以访问其他无法解析为 XML.
使用 Altova XMLSpy 分别是 RaptorXML 和 XSLT 3.0 你也可以使用 uri-collection
,似乎访问所有 .txt
文件的方式有点不同来自 Saxon,您使用 uri-collection('*.txt')
访问目录中的所有 .txt
文件。