我有一个包含大量文件的目录,其中一些文件遵循命名约定001.xml、002.xml、003.xml等。我也有一个XSLT样式表,希望应用于其中的每个文件,而不是目录中的其他文件。我希望将所有这些转换的输出保存在conversions目录中。
在XProc中,我可以使用以下方法手动完成每个转换:
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0" name="transformations">
<p:input port="source" sequence="true"/>
<p:output port="result"></p:output>
<p:xslt name="first">
<p:input port="source">
<p:document href="001.xml"/>
</p:input>
<p:input port="stylesheet">
<p:document href="converter.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:store href="conversions/001.converted.xml" method="xml" indent="true"/>
<p:xslt name="second">
<p:input port="source">
<p:document href="002.xml"/>
</p:input>
<p:input port="stylesheet">
<p:document href="converter.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:store href="conversions/002.converted.xml" method="xml" indent="true"/>
<p:xslt name="third">
<p:input port="source">
<p:document href="003.xml"/>
</p:input>
<p:input port="stylesheet">
<p:document href="converter.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
</p:declare-step>以p:store作为中间文件保存的前两个转换文件,最后一个通过在oXygen中配置结果输出端口来保存。
我想了解如何在遵循XProc命名约定的目录中的所有文件上使用\d+\.xml进行此操作。我已经多次阅读了关于我的技能水平的XProc文档,查看了现有的在线示例,并且我理解有一些东西,比如p:for-each、p:directory-list,有过滤属性等等,但是对于我的生活,我不知道如何将这些东西组合在一起。
我非常感谢你的帮助。
发布于 2022-03-20 08:51:40
若要使用p:xslt处理您的目录筛选文件列表,可以使用。
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0" xpath-version="2.0">
<p:output port="result" sequence="true"/>
<p:directory-list include-filter="00[0-9].xml" path="."></p:directory-list>
<p:for-each>
<p:iteration-source select="//c:file/doc(@name)"></p:iteration-source>
<p:xslt>
<p:input port="source"></p:input>
<p:input port="stylesheet">
<p:document href="converter.xsl"></p:document>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
</p:for-each>
</p:declare-step>https://stackoverflow.com/questions/71543966
复制相似问题