I want a macro to expand to an attribute or not depending on whether the
value is an empty string or not. Suppose I have the following script:
 
<?xml version="1.0"?>
<!DOCTYPE project []>
<project name="foo" default="foo">
  <macrodef name="foomac">
    <attribute name="attr"/>
    <sequential>
    <echo @{attr}>Running macro</echo>
    </sequential>
  </macrodef>
 
  <target name="foo">
    <foomac attr="file=&quot;bar&quot;"/>
  </target>
</project>

I want to optionally include an attribute to the <echo> element if the
parameter is given as the non-empty string (I'm not really doing this
with <echo>. This is an example).
 
Any other way to do this? Macros seem great for optionally including
elements and parts of strings but not so great for attributes.
 
 

Reply via email to