在我的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
时读取名为path的属性的值。
这就是我尝试的:
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>
不理解您的问题。使用给定文件:
<?xml version="1.0" encoding="UTF-8"?>
<set-up>
<processor name="xalan" path="../../library/xalan-j_2_7_2/xalan.jar"/>
</set-up>
和xmlproperty任务:
<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