2010-08-21 56 views
0

我正在嘗試使用ant來使用XSLT預處理我的項目中的三個特定樣式表。 Ant documentation for the xslt task表示它應該能夠接受任何資源收集。具體來說,它說:如何在ant中指定xml文檔進行資源收集轉換?

使用資源集合來指定樣式表應該應用到的資源。使用嵌套映射器和任務的destdir屬性來指定輸出文件。

因此,我試圖使用文件集指定這些樣式表,並將該文件集用作xslt任務中的嵌套元素,但到目前爲止還沒有工作。相反,它會做的是看似忽略指定的文件集,並掃描整個項目中以.xsl結尾的文件,將樣式表應用於這些文件,並根據映射器中指定的邏輯命名輸出。

<fileset id="stylesheets-to-preprocess" dir="${basedir}"> 
    <filename name="src/xslt/backends/js/StatePatternStatechartGenerator.xsl"/> 
    <filename name="src/xslt/backends/js/StateTableStatechartGenerator.xsl"/> 
    <filename name="src/xslt/backends/js/SwitchyardStatechartGenerator.xsl"/> 
</fileset> 

<!-- ... --> 

<target name="preprocess-stylesheets" depends="init"> 

    <xslt 
     classpathref="xslt-processor-classpath" 
     style="src/xslt/util/preprocess_import.xsl" 
     destdir="build" 
     scanincludeddirectories="false"> 

     <fileset refid="stylesheets-to-preprocess"/> 
     <mapper> 
      <chainedmapper> 
       <flattenmapper/> 
       <globmapper from="*.xsl" to="*_combined.xsl"/> 
      </chainedmapper> 
     </mapper> 
    </xslt> 

</target> 

我想要的是限制它,以便只處理文件集中指定的文件。

刪除映射器,以便文件集是唯一嵌套的元素,將導致ant試圖將轉換應用於每個文件,即使那些沒有xsl擴展名的轉換文件,當它試圖轉換非xml文檔時不可避免地會失敗。

我正在使用ant 1.7.1。任何指導將不勝感激。

回答

2

您的問題是由隱式文件集功能引起的。爲了使用嵌套文件集參數,您需要關閉此功能。

我還建議在文件集中使用「include」參數,要簡單得多,並且避免需要複雜的mapper元素(您必須指定生成文件的擴展名,否則它將默認爲.html )

<target name="preprocess-stylesheets" depends="init"> 

    <xslt 
     classpathref="xslt-processor-classpath" 
     style="src/xslt/util/preprocess_import.xsl" 
     destdir="build" 
     extension=".xsl" 
     useImplicitFileset="false" 
     > 

     <fileset dir="src/xslt/backends"> 
      <include name="StatePatternStatechartGenerator.xsl"/> 
      <include name="StateTableStatechartGenerator.xsl"/> 
      <include name="SwitchyardStatechartGenerator.xsl"/> 
     </fileset> 
    </xslt> 

</target> 
相關問題