Ant xslt task output to stdout

心已入冬 提交于 2019-12-22 10:10:13

问题


Using the <xslt> task in ant, how do I get the output to generate to stdout?

My XSLT is generating multiple files through xsl:result-document and the normal output is just status information that I'd like to show up with normal Ant output. Ant seems to force me to supply a destdir= or an out= parameter.

Ant 1.8.2 with Saxon 9


回答1:


Yes ant does this. However XSLT has the element which you can use to get output on the stdout :)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="types" match="a" use="text()"/>
<xsl:template match="/">
<result>
  <xsl:message terminate="no">I am a message from xslt!</xsl:message>
</result>
</xsl:template>
</xsl:stylesheet>

Output :

build:
 [xslt] Processing C:\Users\Stefanos\Documents\Visual Studio 2010\Projects\stackOverflow\stackOverflow\test.xml to C:\Users\Stefanos\Documents\Vis
ual Studio 2010\Projects\stackOverflow\stackOverflow\out.xml
 [xslt] Loading stylesheet C:\Users\Stefanos\Documents\Visual Studio 2010\Projects\stackOverflow\stackOverflow\test.xslt
 [xslt] I am a message from xslt!

BUILD SUCCESSFUL
Total time: 0 seconds

Hope it helps!




回答2:


I recently had a similar scenario; an Ant script with an XSLT task where the style sheet transform generated multiple files using <xsl:result-document>. Since the Ant XSLT task requires the destdir attribute (unless the out attribute has been specified), I used known temp file(s) for the out destination and then implemented a “cleanup” task which deleted the temp file(s).

<target name="removeTemporaryFiles" description="remove temporary files">
    <delete file="${workspace}/temp.xhtml"></delete>
…
</target>


来源:https://stackoverflow.com/questions/7575283/ant-xslt-task-output-to-stdout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!