代码之家  ›  专栏  ›  技术社区  ›  jbeard4

如何在ant中指定xml文档进行资源集合转换?

  •  0
  • jbeard4  · 技术社区  · 16 年前

    我正在尝试使用ant来使用XSLT预处理我的项目中的三个特定样式表。这个 Ant documentation for the xslt task 表示它应该能够接受任何资源集合。具体来说,它说:

    使用资源集合指定样式表应应用于的资源。使用嵌套映射器和任务的destdir属性指定输出文件。

    <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>
    

    我想限制它,以便只处理文件集中指定的那些文件。

    删除映射器,使fileset成为唯一的嵌套元素,这将导致ant试图将转换应用于每个文件,甚至是那些没有xsl扩展名的文件,当它试图转换非xml文档时,这将不可避免地失败。

    我用的是Ant1.7.1。任何指导都将不胜感激。

    1 回复  |  直到 16 年前
        1
  •  2
  •   Mark O'Connor    16 年前

    您的问题是由隐式文件集功能引起的。为了使用嵌套的文件集参数,您需要关闭此功能。

    我还建议在文件集中使用一个“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>