4.4. Phase one build

Firstly, initialisation, for completeness. In this example it serves no purpose and may be omitted.

Example 9. Initialisation, a preparatory task

 <!--  -->
 <!--Initial processing: If needed.  -->
 <!--  -->
 <target name="init">
	<echo message="Do initialisational things" />                   
  <tstamp>                                              1
   <format property="TODAY_UK" pattern="d-MMM-yyyy" locale="en"/>
  </tstamp>
 <echo>building on ${TODAY_UK}</echo>                2
 </target>  

1

This code produces a formatted time value

2

The echo command prints output to the terminal


To get this out of the way. Sometimes it is useful to carry out some housekeeping prior to running a task. Typically this might be removing all the files in the html directory (if you want to ensure that only new files are created). This is the place to do it. All this example does is to echo the time at which the operation started.

Now the actual phase 1 build i shown in Example 10.

Example 10. Layout processing

 <!-- ================================================ -->
    <!--      Use layout to create autolayout.xml             -->
    <!--      Needs to be run if files are added to the Website       -->
    <!-- ================================================ -->
    <target name="layout" depends="init">  
    <echo message="Website, first stage processing " />     
    <java classname="${xslt.processor.class}"               1             
      fork="yes" 
      dir="${in.dir}"
      failonerror="true">                                      2
      <classpath refid="xslt.processor.classpath" />
      <arg line="-o ${autolayout.outfile}"/>                3
      <arg line="-x org.apache.xml.resolver.tools.ResolvingXMLReader"/>       4
      <arg line="-y org.apache.xml.resolver.tools.ResolvingXMLReader"/>
      <arg line="-r org.apache.xml.resolver.tools.CatalogResolver"/>          5
      <arg line="${in.dir}/${autolayout.infile} ${autolayout.stylesheet} ${param.args.post}" />  6
    </java>
    </target>

1

This parameter specifies the xslt engine to use, previously set to saxon

2

What to do in case of an xslt transformation error. Stop!

3

The output file from this transformation, autolayout.xml - as requested

4

This tells the parser to resolve any references using the Apache resolver (to be explained later...)

5

This brings the catalog resolver into play. Again, more later...

6

These are the input file ($autolayout.infile = layout.xml), the stylesheet ($autolayout.stylesheet = autolayout.xsl) and the specification of a final parameter to the transform engine, to use the extensions provided by Website, which are not normally available to XSLT 1.0, and are provided by this extension.


That's the full transformation. Of note is the error processing. It is advisable to have the system stop processing on finding an error. Otherwise you could be uploading nothing, or old files to your Website. If the system stops, the errors will be reported to you on the terminal. That way you can resolve them and re-process the Website.

Try corrupting one of the xml files (remove a closing > from one of the elements and find out what happens! You should find it easy to locate and correct the error.

In order to use this command, assuming the ant script/batch file is accessible from the command prompt, simply change directory to where the build.xml file is located and issue the command

  >ant layout

If there are no errors, the output file autolayout.xml will be created.

Next, phase two build