ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank E. Weiss" <fra...@well.com>
Subject Re: How to implement loop constructs etc.. in ant build file?
Date Sat, 22 Sep 2001 00:50:45 GMT
> > 3. Source contents of an external .xml file into the current
> > build.xml file?
>
> There is no ant specific feature to include other xml files. Alternative
> features that are close are:
> * the "ant" task which invokes a target in another build file
> * the XML's "include" feature using entities

You're forgetting the best one - XSLT. For example:

<target name="cook-alpha" depends="take1/cook.xsl">
     <style
        style="take1/cook.xsl"
        in="xml/alpha_index.xml"
        out="take1/build-alpha.xml"
    />
    <ant antfile="take1/build-alpha.xml"/>
</target>

What this does: The cook.xsl stylesheet outputs an 'ant' xml document. It uses
the alpha_index.xml document to get a set of files that need to be 'cooked'. The
ant xml document it puts out, build-alpha.xml, has one ant target with a set of
'get' commands for each file it found in alpha_index.xsl. That ant file is then
input to an ant subprocess. It's similar to using awk to build a shell file and
then feeding awk's output to a subshell.

Here's the cook.xsl stylesheet:
<xsl:stylesheet
 version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <!-- cook an asp page into static html -->
 <!-- input document contains set of possible keys -->

 <xsl:output method="xml" indent="yes"/>

 <xsl:template match="alpha-index">
  <project name="cooker" default="build-alpha" basedir="..">
   <target name="build-alpha">
    <xsl:for-each select="alpha-key">
     <get>
      <xsl:attribute name="src">
       <xsl:value-of
select="concat('http://localhost/asp-bin/alpha_index.asp?cook=1&amp;alphakey=',
node())"/>
      </xsl:attribute>
      <xsl:attribute name="dest">
       <xsl:value-of select="concat('w:/html/alpha_index.', node(), '.html')"/>
      </xsl:attribute>
     </get>
    </xsl:for-each>
   </target>
  </project>
 </xsl:template>


</xsl:stylesheet>




Mime
View raw message