如何简化这个xproc管道?

时间:2010-10-08 18:50:09

标签: xml pipeline saxon xproc

我刚刚开始深入研究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>

2 个答案:

答案 0 :(得分:5)

我转向xproc-dev邮件列表寻求帮助,我很快就找到了解决方案proposedimplemented。这使我能够将上面的管道简化为此(更改名称空间以保护无辜者):

<?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>,所以主流水线文件比这更简单。)

答案 1 :(得分:0)

我看不到简化管道的方法......除非您自己修改样式表。例如。制作一个导入所有其他样式表的样式表,并将其中一个的输出传递给下一个的输入。 (这将需要XSLT 2.0或exsl:nodeset扩展。)

但不,我没有看到简化XProc管道而不修改其他东西的方法。