Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 宏定义属性不会更改其值_Java_Xml_Xslt_Ant_Ant Contrib - Fatal编程技术网

Java 宏定义属性不会更改其值

Java 宏定义属性不会更改其值,java,xml,xslt,ant,ant-contrib,Java,Xml,Xslt,Ant,Ant Contrib,在上一篇文章中,我试图实现macrodef,以便用“类似函数”的任务替换重复的代码块。然后我遇到了一些问题。之后,我减少了脚本,这样我就可以尝试我不习惯的任务。这是我编的: <project basedir="../../../" name="do-report" default="extract-common-paths"> <xmlproperty keeproot="false" fi

在上一篇文章中,我试图实现
macrodef
,以便用“类似函数”的任务替换重复的代码块。然后我遇到了一些问题。之后,我减少了脚本,这样我就可以尝试我不习惯的任务。这是我编的:

<project basedir="../../../" name="do-report" default="extract-common-paths">
    <xmlproperty keeproot="false" file="implementation/xml/ant/properties.xml"/>
    <!--    -->
    <taskdef resource="net/sf/antcontrib/antlib.xml">
        <classpath>
            <pathelement location="${infrastructure-base-dir}/apache-ant-1.9.6/lib/antcontrib.jar"/>
        </classpath>
    </taskdef>
    <!--    -->
    <macrodef name="get-common-path">
        <attribute name="common-path-property"/>
        <attribute name="file"/>
        <attribute name="file-base-dir"/>
        <sequential>
            <local name="file-dir-absolute-path"/>
            <dirname property="file-dir-absolute-path" file="@{file}"/>
            <property name="file-base-dir-absolute-path" location="@{file-base-dir}"/>
            <echo>MACRODEF FILE: ${file-dir-absolute-path}</echo>
            <echo>MACRODEF FILE-BASE-DIR: ${file-base-dir-absolute-path}</echo>
            <pathconvert property="@{common-path-property}" dirsep="/">
                <path location="${file-dir-absolute-path}"/>
                <map from="${file-base-dir-absolute-path}/" to=""/>
            </pathconvert>
        </sequential>
    </macrodef>
    <!--    -->
    <target name="clean">
        <delete dir="${dita-odt.path.odt-unzipped-base-dir}" includeemptydirs="true" failonerror="no"/>
        <delete dir="examples/intermediate/odt-files" includeemptydirs="true" failonerror="no"/>
    </target>
    <!--    -->
    <target name="unzip-writing-odt-file" depends="clean">
        <unzip src="${dita-odt.path.writing-odt}" dest="${dita-odt.path.writing-odt-unzipped}"/>
    </target>
    <!--    -->
    <target name="extract-common-paths" depends="unzip-writing-odt-file">
        <for param="file">
            <path>
                <fileset dir="${dita-odt.path.text-xml-base-dir}">
                    <include name="**/content.xml"/>
                </fileset>
            </path>
            <sequential>
                <get-common-path common-path-property="common-path" file="@{file}" file-base-dir="${dita-odt.path.text-xml-base-dir}"/>
                <echo>THIS IS THE PATH: ${common-path}</echo>
            </sequential>
        </for>
    </target>
</project>

宏定义文件:${FILE dir绝对路径}
宏定义FILE-BASE-DIR:${FILE-BASE-DIR绝对路径}
这是路径:${common PATH}
FOR
任务迭代不同目录中的两个文件。实际上,的
工作正常。它按其应该的方式传递
${file}
<代码>宏定义
属性公共路径属性首先设置为第一个文件的转换路径(可以)。但是,当第二个文件被传递到
get common path/@file
时,属性
common path属性
不会更改其值,我再次收到:

[echo]宏定义文件:C:\Users\rmrd001\git\xslt framework\examples\text\t1\t1.1

[echo]MACRODEF FILE-BASE-DIR:C:\Users\rmrd001\git\xslt framework\examples\text

[echo]这是路径:t1/t1.1

[echo]宏定义文件:C:\Users\rmrd001\git\xslt framework\examples\text\t2\t2.1

[echo]MACRODEF FILE-BASE-DIR:C:\Users\rmrd001\git\xslt framework\examples\text

[echo]这是路径:t1/t1.1

相反,我希望收到:

[echo]宏定义文件:C:\Users\rmrd001\git\xslt framework\examples\text\t1\t1.1

[echo]MACRODEF FILE-BASE-DIR:C:\Users\rmrd001\git\xslt framework\examples\text

[echo]这是路径:t1/t1.1

[echo]宏定义文件:C:\Users\rmrd001\git\xslt framework\examples\text\t2\t2.1

[echo]MACRODEF FILE-BASE-DIR:C:\Users\rmrd001\git\xslt framework\examples\text

[echo]这是路径:\t2\t2.1


我希望你明白我想做什么。提前谢谢你

尝试打印macrodef属性值而不是属性值

  • @{attribute}
    -每次执行宏定义时都会发生变化
  • ${property}
    -始终在Ant中设置和修复一次,并且仅在Ant中设置和修复一次,即使在宏定义中也是如此
    • 除非前面有
      任务,否则在这种情况下,本地设置的属性值将在该块的范围内使用
也许你想要的是蚂蚁提供的

将本地属性添加到当前范围。属性作用域存在于 ApacheAnt的各种“块”级别