简体   繁体   English

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

[英]How to specify xml documents to transform with resource collection in ant?

I'm trying to use ant to use XSLT to preprocess three specific stylesheets in my project. 我正在尝试使用ant来使用XSLT预处理项目中的三个特定样式表。 The Ant documentation for the xslt task says that it should be able to accept any resource collection. xslt任务Ant文档说它应该能够接受任何资源收集。 Specifically, it says: 具体来说,它说:

Use resource collections to specify resources that the stylesheet should be applied to. 使用资源集合来指定应将样式表应用于的资源。 Use a nested mapper and the task's destdir attribute to specify the output files. 使用嵌套的映射器和任务的destdir属性来指定输出文件。

I've therefore tried to specify these stylesheets using a fileset, and use the fileset as a nested element in the xslt task, but so far this hasn't been working. 因此,我尝试使用文件集指定这些样式表,并将该文件集用作xslt任务中的嵌套元素,但到目前为止,此方法一直没有奏效。 Instead, what it will do is seemingly ignore the specified fileset, and scan the entire project for files ending in .xsl, apply the stylesheet to those, and name the output according to the logic specified in the mapper. 相反,它的作用似乎是忽略指定的文件集,并扫描整个项目中以.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>

What I'd like is to restrict it so that only those files specified in the fileset are processed. 我想要限制它,以便仅处理文件集中指定的那些文件。

Removing the mapper, so that the fileset is the only nested element, will result in ant attempting to apply the transformation to every file, even those without xsl extensions, which inevitably fails when it tries to transform a non-xml document. 删除映射器,使文件集是唯一的嵌套元素,将导致ant试图将转换应用于每个文件,即使是那些没有xsl扩展名的文件,当它尝试转换非xml文档时也不可避免地失败。

I'm using ant 1.7.1. 我正在使用ant 1.7.1。 Any guidance would be appreciated. 任何指导将不胜感激。

Your problem is being caused by the implicit fileset functionality. 您的问题是由隐式文件集功能引起的。 In order to use a nested fileset parameter you need to switch this feature off. 为了使用嵌套文件集参数,您需要关闭此功能。

I'd also recommend using an "include" parameter within the fileset, much simpler, and avoids the need for a complicated mapper element (You must specify the extension of the generated files, otherwise it'll default to .html) 我还建议在文件集中使用“ 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM