在我的build.xml中,我需要创建一个具有名称和位置属性的属性。该位置是xslt处理器的相对路径。问题是必须从xml
文件导入此路径(位置属性值)。
在这个例子中:
<property name="processor_path" location="../../library/xalan-j_2_7_2/xalan.jar"/>
这部分:../../library/xalan-j_2_7_2/xalan.jar
必须从这里提取:
<?xml version="1.0" encoding="UTF-8"?>
<set-up>
<processor name="xalan" path="../../library/xalan-j_2_7_2/xalan.jar"/>
</set-up>
换句话说,不是手动键入处理器的路径,而是构建本身以读取xml,并在找到set-up.processor
时读取属性命名路径的值。
这就是我的尝试:
xml文件:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<processor>
<property name="path" location="../../library/saxon-he-9-6-0-7j/saxon9he.jar"/>
</processor>
<test-case name="test-case-1">
<object-under-test category="template" name="text-align"/>
<parameters>
<input name="text">text</input>
<input name="min-lenght">8</input>
<input name="align">left</input>
<output name="result"/>
</parameters>
<criteria>
<criterion class="equal" to="'text '"/>
</criteria>
</test-case>
这是build.xml
:
<project name="TranformXml" default="report">
<xmlproperty file="../test-cases/test-case-1.xml" collapseAttributes="true"/>
<property name="processor_path" location="${processor.path}"/>
<property name="output_path" location="../test-report"/>
<property name="input_path" location="../test-cases"/>
<target name="clean">
<delete file="stylesheet-2.xsl"/>
<delete file="${output_path}/report.xml"/>
</target>
<target name="do-stylesheet-2">
<xslt in="${input_path}/test-case-1.xml" out="stylesheet-2.xsl" style="stylesheet-1.xsl" force="true">
<classpath location="${processor_path}" />
</xslt>
</target>
<target name="do-report" depends="do-stylesheet-2">
<xslt in="stylesheet-2.xsl" out="${output_path}/report.xml" style="stylesheet-2.xsl" force="true">
<classpath location="${processor_path}" />
</xslt>
</target>
<target name="report" depends="do-report" />
</project>
答案 0 :(得分:0)
不明白你的问题。给定文件:
<?xml version="1.0" encoding="UTF-8"?>
<set-up>
<processor name="xalan" path="../../library/xalan-j_2_7_2/xalan.jar"/>
</set-up>
<project>
<xmlproperty file="xmlprops.xml" collapseattributes="true"/>
<echoproperties prefix="set-up"/>
</project>
你将获得财产set-up.processor.path
输出:
[echoproperties] #Ant properties
[echoproperties] #Thu Oct 29 08:22:52 CET 2015
[echoproperties] set-up.processor=
[echoproperties] set-up.processor.name=xalan
[echoproperties] set-up.processor.path=../../library/xalan-j_2_7_2/xalan.jar