ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: help! Can't I set a <property> more than once in a build file?
Date Thu, 20 Jul 2000 12:12:10 GMT

Here's an XSL transform that might help, but it doesn't do everything.
It'll transform

<target name="blah">
  <property name="param1" value="test1"/>
  <ant antfile="sub1/build.xml"/>


<target name="blah>
  <ant antfile="sub1/build.xml>
    <property name="param1" value="test1"/>

but it turns this

<target name="blah2">
  <property name="param1" value="test1"/>
  <ant antfile="sub1/build.xml" />

  <property name="param1" value="some_other_value"/>
  <ant antfile="sub2/build.xml" />


<target name="blah2">
  <ant antfile="sub1/build.xml" >
    <property name="param1" value="test1" />

  <ant antfile="sub2/build.xml" >
    <property name="param1" value="test1" />

The problem comes with XSL's understanding of siblings and selecting.  I
can tell it to select the previous siblings to the ant element, and pick
the property element with a name attribute of "param1".  The problem is
that if there is more than one, it ALWAYS picks the first one.  I tried
using variables, but they don't scope properly.

If someone can come up with a more general solution, please let us know!

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=""
  <xsl:output method="xml"/>
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:variable name="param1_value">dummy_value</xsl:variable>

  <!-- The identity transformation that keeps us from having to deal with
       every element. -->
  <xsl:template match="*|@*|comment()|processing-instruction()|text()">

  <!-- this simplistic rule assumes that _every_ ant task needs to be
modified -->
  <xsl:template match="ant">
      <xsl:attribute name="antfile"><xsl:value-of
      <!-- put your custome properties here -->
      <property name="param1">
        <xsl:attribute name="value"><xsl:value-of


  <xsl:template match="property">
      <!-- test for the properties you want to remove, and do nothing when
you find them -->
      <xsl:when test="@name='param1'"><xsl:variable
      <!-- otherwise, leave all other properties alone (just write them out
again) -->
        <xsl:copy><xsl:apply-templates select="@*"/></xsl:copy>


Glenn McAllister
TID - Software Developer - VisualAge for Java
IBM Toronto Lab, (416) 448-3805
"An approximate answer to the right question is better than the
right answer to the wrong question." - John W. Tukey

Please respond to

Subject:        RE: help! Can't I set a <property> more than once in a
build file?

Could you write a few lines of sample XSL for this?
It seems like it would be an easy task to change my non-nested properties
into nested ones using XSL.

An example might be useful for others who have the same problem as me.


> -----Original Message-----
> From: []
> Sent: Wednesday, July 19, 2000 5:11 PM
> To:
> Subject: RE: help! Can't I set a <property> more than once in a build
> file?
> :-) Check out XSL.  I used it to transform 430 odd custom XML config
> into one coherent (and easier to use, despite the size) build file.

View raw message