Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
源文件数目可变的XSLT工作流_Xslt_Workflow_Saxon_Xproc - Fatal编程技术网

源文件数目可变的XSLT工作流

源文件数目可变的XSLT工作流,xslt,workflow,saxon,xproc,Xslt,Workflow,Saxon,Xproc,我有一堆XML文件,它们具有固定的、基于国家/地区的命名模式:report\u en.XML、report\u de.XML、report\u fr.XML,等等。现在我想编写一个XSLT样式表,通过document()XPath函数读取每个文件,提取一些值并生成一个带有摘要的XML文件。我的问题是:在不知道要处理的文件的确切名称的情况下,如何迭代源文件? 目前,我计划生成一个包含所有文件名的辅助XML文件,并使用样式表中的辅助XML文件进行迭代。文件列表将由一个小PHP或bash脚本生成。有更

我有一堆XML文件,它们具有固定的、基于国家/地区的命名模式:
report\u en.XML
report\u de.XML
report\u fr.XML
,等等。现在我想编写一个XSLT样式表,通过
document()
XPath函数读取每个文件,提取一些值并生成一个带有摘要的XML文件。我的问题是:在不知道要处理的文件的确切名称的情况下,如何迭代源文件?

目前,我计划生成一个包含所有文件名的辅助XML文件,并使用样式表中的辅助XML文件进行迭代。文件列表将由一个小PHP或bash脚本生成。有更好的选择吗

我知道,但投入大量时间在这方面目前对我来说不是一个选择。也许有人可以发布XProc解决方案。该解决方案最好包括工作流步骤,其中报告以HTML形式下载并整理:)


我将使用Saxon作为XSLT处理器,因此如果有特定于Saxon的扩展,这些扩展也可以使用。

您可以使用标准XPath 2.x函数,

Saxon实现允许在函数的字符串Uri参数中使用搜索模式,因此您可以在目录路径之后为任何文件名指定一个模式,该文件名以
report\uuu
开头,然后有两个其他字符,然后以
.xml
结尾

示例

此XPath表达式:

collection('file:///c:/?select=report_*.xml')

选择文件中驻留在
c:\
中的每个XML文档的文档节点,文件名以
report\uUcode>开头,然后有0个或更多字符,然后以
结尾。XML

Dimitre的答案看起来是您案例中最快的解决方案。但既然你问了,这里有一个XProc替代方案:

<p:declare-step version="1.0" xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" exclude-inline-prefixes="#all" name="main">

<!-- create context for p:variable with base-uri pointing to the location of this file -->
<p:input port="source"><p:inline><x/></p:inline></p:input>

<!-- any params passed in from outside get passed through to p:xslt automatically! -->
<p:input port="parameters" kind="parameter"/>

<!-- configuration options for steering input and output -->
<p:option name="input-dir" select="'./'"/>
<p:option name="input-filter" select="'^report_.*\.xml$'"/>
<p:option name="output-dir" select="'./'"/>

<!-- resolve any path to base uri of this file, to make sure they are absolute -->
<p:variable name="abs-input-dir" select="resolve-uri($input-dir, base-uri(/))"/>
<p:variable name="abs-output-dir" select="resolve-uri($output-dir, base-uri(/))"/>

<!-- first step: get list of all files in input-dir -->
<p:directory-list>
    <p:with-option name="path" select="$abs-input-dir"/>
</p:directory-list>

<!-- iterate over each file to load it -->
<p:for-each>
    <p:iteration-source select="//c:file[matches(@name, $input-filter)]"/>
    <p:load>
        <p:with-option name="href" select="resolve-uri(/c:file/@name, $abs-input-dir)"/>
    </p:load>
</p:for-each>

<!-- wrap all files in a reports element to be able to hand it in to the xslt as a single input document -->
<p:wrap-sequence wrapper="reports"/>

<!-- apply the xslt (stylesheet is loaded below) -->
<p:xslt>
    <p:input port="stylesheet">
        <p:pipe step="style" port="result"/>
    </p:input>
</p:xslt>

<!-- store the result in the output dir -->
<p:store>
    <p:with-option name="href" select="resolve-uri('merged-reports.xml', $abs-output-dir)"/>
</p:store>

<!-- loading of the stylesheet.. -->
<p:load href="process-reports.xsl" name="style"/>

</p:declare-step>
上面的代码假设一个process-reports.xsl,它接受一个封装所有报告的文档,并对其进行一些处理。您也可以使用纯XProc进行处理,但您可能更喜欢这种方式

您还可以将p:xslt步骤上移到p:for-each中(p:load下面),这将导致xslt分别应用于每个报表

祝你好运

好问题(+1)。请参阅我的答案以获得一个可能的解决方案。
java -jar calabash.jar process-reports.xpl input-dir=./ output-dir=./