使用相同的输入和输出文件使用ant xslt任务
似乎不可能运行ant xslt任务来对xml进行排序(例如),使用输入文件作为输出文件,而不使用任何临时文件 我使用以下目标对所有arxml文件的内容进行排序使用相同的输入和输出文件使用ant xslt任务,xslt,ant,Xslt,Ant,似乎不可能运行ant xslt任务来对xml进行排序(例如),使用输入文件作为输出文件,而不使用任何临时文件 我使用以下目标对所有arxml文件的内容进行排序 <target name="sort_arxml" depends="init" description="Do a XLST on all arxml files to sort their content"> <tempfile property="sort.xslt" suffix=".xslt" dele
<target name="sort_arxml" depends="init" description="Do a XLST on all arxml files to sort their content">
<tempfile property="sort.xslt" suffix=".xslt" deleteonexit="true" />
<echo file="${sort.xslt}">
<![CDATA[
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:sort select="child::*"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
]]></echo>
<xslt style="${sort.xslt}" basedir="../Config" destdir="../Config" extension=".arxml" includes="**/*.arxml" excludes="**/AUTOSAR*"/>
</target>
不能同时对同一文件进行读写操作 您必须选择另一个输出文件名(或其他文件夹),然后用新文件替换旧文件
默认情况下,ant会覆盖现有文件。您不能同时对同一文件进行读写 您必须选择另一个输出文件名(或其他文件夹),然后用新文件替换旧文件 默认情况下,ant会覆盖现有文件。XSLT本身无法写入其输入文件,因此ant XSLT任务无法帮助您实现目标。 顺便说一句,创建临时文件或目录没有什么错,将XSLT输入与输出分开也有好处。ant XSLT任务可以检测何时需要重新运行转换,并且当输入和输出文件不同时,可以方便地进行调试。你最好不要违背规则 如果您不能围绕输出文件与输入文件相同的需求进行设计,只需写入一个单独的输出目录,并在转换后用输出目录替换输入目录:
<target name="sort_arxml" depends="init"
description="Do a XLST on all arxml files to sort their content">
<!-- [ same as in question ] -->
<xslt style="${sort.xslt}" basedir="../Config" destdir="../ConfigTMP"
extension=".arxml" includes="**/*.arxml" excludes="**/AUTOSAR*"/>
<delete dir="../Config"/>
<move file="../ConfigTMP" tofile="../Config"/>
</target>
XSLT本身无法写入其输入文件,因此ant XSLT任务无法帮助您实现目标。
顺便说一句,创建临时文件或目录没有什么错,将XSLT输入与输出分开也有好处。ant XSLT任务可以检测何时需要重新运行转换,并且当输入和输出文件不同时,可以方便地进行调试。你最好不要违背规则
如果您不能围绕输出文件与输入文件相同的需求进行设计,只需写入一个单独的输出目录,并在转换后用输出目录替换输入目录:
<target name="sort_arxml" depends="init"
description="Do a XLST on all arxml files to sort their content">
<!-- [ same as in question ] -->
<xslt style="${sort.xslt}" basedir="../Config" destdir="../ConfigTMP"
extension=".arxml" includes="**/*.arxml" excludes="**/AUTOSAR*"/>
<delete dir="../Config"/>
<move file="../ConfigTMP" tofile="../Config"/>
</target>
谢谢您的全面回答谢谢您的全面回答
<target name="sort_arxml" depends="init"
description="Do a XLST on all arxml files to sort their content">
<!-- [ same as in question ] -->
<xslt style="${sort.xslt}" basedir="../Config" destdir="../ConfigTMP"
extension=".arxml" includes="**/*.arxml" excludes="**/AUTOSAR*"/>
<delete dir="../Config"/>
<move file="../ConfigTMP" tofile="../Config"/>
</target>