I have an ant “properties” file that looks like this (although I can adjust the format if needed – I can make it an XML file if that’s more appropriate):
libraries.properties
name 1
http://www.url1.com?a=b
name 2
http://www.url2.com?c=d
name 3
http://www.url3.com?e=f
NOTE: I know this is not a valid properties format because it’s not in the form a=b. I can change it to anything that’s appropriate, as long as it’s easy to add entries in future.
I want ant to take a file that is checked-in as follows:
options.html (source)
<select>
<option value="@URL@">@NAME@</option>
</select>
… and do a search and replace on the tokens as many times as there are name/value entries in libraries.properties, so the resulting options.html file would look like this:
options.html (after build)
<select>
<option value="http://www.url1.com?a=b">name 1</option>
<option value="http://www.url2.com?c=d">name 2</option>
<option value="http://www.url3.com?3=f">name 3</option>
</select>
As with the properties file, the options.html source can be a different format. I just need some way of defining what I copy from/to.
What’s the cleanest way to do this?
Thanks!
What you need is a templating engine to generate your HTML file.
The closest thing to this that ANT directly supports is an XSLT transformation.
Example
The following project
When run generates a single HTML file
Note, this is not a properly formatted HTML file. Your specification looks more like a fragment designed to be imported into another file.
properties.xml
options.xsl
build.xml