代码之家  ›  专栏  ›  技术社区  ›  Will McCutchen

如何简化这个xproc管道?

  •  4
  • Will McCutchen  · 技术社区  · 14 年前

    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 回复  |  直到 14 年前
        1
  •  5
  •   Will McCutchen    14 年前

    我转向 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> 因此,主管道文件甚至比它更简单。)

        2
  •  0
  •   LarsH    14 年前

    我看不到简化管道的方法。。。除非修改样式表本身。例如。制作一个样式表,该样式表导入所有其他样式表,并将一个样式表的输出传递给下一个样式表的输入。(这需要XSLT2.0条或者exsl:nodeset扩展名。)

    但不,我看不到在不修改其他内容的情况下简化XProc管道的方法。