ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gle...@ca.ibm.com
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>

into

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

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>

into

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

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

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="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <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()">
    <xsl:copy>
      <xsl:apply-templates
       select="*|@*|comment()|processing-instruction()|text()"/>
    </xsl:copy>
  </xsl:template>

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

      </property>
    </ant>
  </xsl:template>

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


</xsl:stylesheet>

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 ant-dev@jakarta.apache.org

To:        ant-dev@jakarta.apache.org
cc:
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.

Ken

> -----Original Message-----
> From: glennm@ca.ibm.com [mailto:glennm@ca.ibm.com]
> Sent: Wednesday, July 19, 2000 5:11 PM
> To: ant-dev@jakarta.apache.org
> 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
files
> into one coherent (and easier to use, despite the size) build file.
>





Mime
View raw message