1

我想读取如下 XML 文件

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.ibm.ws.st.core.runtimeClasspathProvider/com.ibm.worklight"/>
  <classpathentry kind="con" path="com.worklight.studio.plugin.classpath.SERVER_CONTAINER"/>
  <classpathentry kind="src" path="server/java"/>
  <classpathentry kind="src" path="common"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <classpathentry kind="src" output="adapters/adp1/bin" path="adapters/agent/src"/>
  <classpathentry kind="src" output="adapters/adp2/bin" path="adapters/alerts/src"/>
  <classpathentry kind="src" output="adapters/adp3/bin" path="adapters/billing/src"/>
  <classpathentry kind="src" output="adapters/adp4/bin" path="adapters/client/src"/>
  <classpathentry kind="src" output="adapters/adp5/bin" path="adapters/category/src"/>
</classpath>

我想读取pathwhere kindis的值"src"。我能够获得所有路径值,但无法暗示它的条件。我正在使用以下代码。

<target name="xml">
  <echo>Test For Each</echo>
  <for list="${classpath.classpathentry.path}" param="letter" delimiter=",">
    <sequential>
      <echo message="path :::  @{letter}"/>
    </sequential>
  </for>
</target>   

它适用于所有path值,但我应该怎么做才能获得pathwhere kindis的值"src"

4

1 回答 1

2

正如我在评论中所说,以下 XSLT 将解析 kind=src 的所有类路径条目并生成单行路径语句。

getclasspath.xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/classpath">
        <xsl:text>path=</xsl:text>
        <xsl:for-each select="classpathentry[@kind='src']">
            <xsl:value-of select="@path"/>
            <xsl:text>;</xsl:text>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

然后是下面的蚂蚁任务:

<xslt style='getclasspath.xslt' in='classpath.xml' out='classpath.properties' />
于 2015-06-19T18:54:45.640 回答