我刚刚开始研究XProc (使用Calabash)。我想对一个输入文档应用一系列XSLT转换,以生成一个输出文档。我以前使用一个简单的Python脚本来驱动转换,但是看起来XProc可能是一个很好的选择。
下面的管道似乎对我很有效。它本质上只是需要按正确顺序应用的XSLT转换的列表。问题是,它看起来非常多余。我希望有一些方法可以减少这一点,但(到目前为止)我自己还不能解决这个问题。
<?xml version="1.0"?>
<p:pipeline version="1.0" xmlns:p="http://www.w3.org/ns/xproc">
<p:xslt name="remove-locations">
<p:input port="stylesheet">
<p:document href="preprocessors/remove-locations.xsl"/>
</p:input>
</p:xslt>
<p:xslt name="divisions-1">
<p:input port="stylesheet">
<p:document href="preprocessors/divisions-1.xsl"/>
</p:input>
</p:xslt>
<p:xslt name="divisions-2">
<p:input port="stylesheet">
<p:document href="preprocessors/divisions-2.xsl"/>
</p:input>
</p:xslt>
<p:xslt name="subjects-1">
<p:input port="stylesheet">
<p:document href="preprocessors/subjects-1.xsl"/>
</p:input>
</p:xslt>
<p:xslt name="subjects-2">
<p:input port="stylesheet">
<p:document href="preprocessors/subjects-2.xsl"/>
</p:input>
</p:xslt>
<p:xslt name="types-1">
<p:input port="stylesheet">
<p:document href="preprocessors/types-1.xsl"/>
</p:input>
</p:xslt>
<p:xslt name="types-2">
<p:input port="stylesheet">
<p:document href="preprocessors/types-2.xsl"/>
</p:input>
</p:xslt>
<p:xslt name="core">
<p:input port="stylesheet">
<p:document href="preprocessors/core.xsl"/>
</p:input>
</p:xslt>
<p:xslt name="consolidate-descriptions">
<p:input port="stylesheet">
<p:document href="preprocessors/consolidate-descriptions.xsl"/>
</p:input>
</p:xslt>
</p:pipeline>发布于 2010-10-13 01:40:48
我向xproc-dev邮件列表寻求帮助,一个解决方案很快就是proposed和implemented。这使我可以将上面的流水线简化为以下内容(更改名称空间以保护无辜者):
<?xml version="1.0"?>
<p:pipeline
version="1.0"
xmlns:p="http://www.w3.org/ns/xproc"
xmlns:ex="http://example.com">
<p:declare-step type="ex:xslt" name="xslt">
<p:input port="source" sequence="true" primary="true"/>
<p:input port="parameters" kind="parameter"/>
<p:output port="result" primary="true"/>
<p:option name="stylesheet" required="true"/>
<p:load name="load-stylesheet">
<p:with-option name="href" select="$stylesheet"/>
</p:load>
<p:xslt>
<p:input port="stylesheet">
<p:pipe port="result" step="load-stylesheet"/>
</p:input>
<p:input port="source">
<p:pipe port="source" step="xslt"/>
</p:input>
</p:xslt>
</p:declare-step>
<ex:xslt stylesheet="remove-locations.xsl"/>
<ex:xslt stylesheet="divisions-1.xsl"/>
<ex:xslt stylesheet="divisions-2.xsl"/>
<ex:xslt stylesheet="subjects-1.xsl"/>
<ex:xslt stylesheet="subjects-2.xsl"/>
<ex:xslt stylesheet="types-1.xsl"/>
<ex:xslt stylesheet="types-2.xsl"/>
<ex:xslt stylesheet="core.xsl"/>
<ex:xslt stylesheet="consolidate-descriptions.xsl" />
</p:pipeline>(实际上,我将步骤分离到自己的文件中并对其进行<p:import>,因此主管道文件甚至比这更简单。)
发布于 2010-10-09 03:55:18
我看不到简化管道的方法..。除非您修改样式表本身。例如,创建一个样式表,导入所有其他样式表,并不断将一个样式表的输出传递给下一个样式表的输入。(这需要XSLT 2.0或exsl:nodeset扩展。)
但是,我没有看到一种不修改其他东西就可以简化XProc管道的方法。
https://stackoverflow.com/questions/3893442
复制相似问题