2010-10-08 21 views
4

我剛開始挖掘XProc(使用Calabash)。我想要將一系列XSLT轉換應用於單個輸入文檔以生成單個輸出文檔。我以前使用簡單的Python腳本來推動轉換,但似乎XProc可能是一個很好的選擇。如何簡化這個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> 

回答

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>,所以主要的管線檔案就更簡單了)

0

我看不到一種方法來簡化管道......除非您自己修改樣式表。例如。使一個樣式表導入所有其他樣式表,並不斷將一個樣式表的輸出傳遞給下一個樣式表的輸入。 (這將需要XSLT 2.0或exsl:nodeset擴展名。)

但是不,我沒有看到如何在不修改其他內容的情況下簡化XProc管道。

+0

這是一個恥辱。看起來這將是一個相當常見的用例,並且會有一些不太詳細的解決方案。 – 2010-10-08 19:57:45

+0

@我會補充一點,我不是一位XProc專家......我剛剛瀏覽了規範和一些教程。我已經在我的願望清單上放了幾個月的XProc。 – LarsH 2010-10-08 20:10:20