2

I have just recently been working with xslt2.0 via ant. I have a build file that looks like so:

<project name="TranformXml" default="TransformFile">
    <target name="TransformFile">
        <xslt in="input.xml"
            out="student.html"
            style="transform.xsl"
            processor="trax" classpath="./lib/saxon/saxon9he.jar">

            <factory name="net.sf.saxon.TransformerFactoryImpl"/>

        </xslt>  
    </target>
</project>

an input document input.xml:

<student_list>
    <student>
        <name>George Washington</name>
        <major>Politics</major>
        <phone>312-123-4567</phone>
        <email>gw@example.edu</email>
    </student>

</student_list>

and stylesheet, transform.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="html"/>

    <xsl:template match="/">
    <html>
        <head>
            <title>Student Directory</title>
        </head>
        <body>
        <xsl:apply-templates />
        </body>

    </html>
    </xsl:template>


</xsl:stylesheet>

and output from my ant build:

ant -f build.xml 
Buildfile: /home/casey/Development/ant-tests/xslt-transform/build.xml

TransformFile:
     [xslt] Processing /home/casey/Development/ant-tests/xslt-transform/input.xml to /home/casey/Development/ant-tests/xslt-transform/student.html
     [xslt] Loading stylesheet /home/casey/Development/ant-tests/xslt-transform/transform.xsl

BUILD SUCCESSFUL
Total time: 9 seconds

I find it hard to believe that it should take 9 seconds to do all this. When in production the stylesheets are going to be alot more complex and the input much larger. Realistically I'd like to keep the whole transform process to less than a few seconds.

Any ideas?

Thanks,

Casey

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
Casey Jordan
  • 1,204
  • 1
  • 20
  • 39
  • I think it's not the transformation itself but the whole process. Running the JVM, parsing documents, compiling the stylesheet and transformation might take some time... –  Apr 01 '11 at 21:19
  • I've had similar issues in the past. Adding `@processor="trax"` and specifying the `` seemed to help. The other issue could be classloader and finding the saxon9he.jar. Testing with your example, it ran in 3 seconds for me(Win7, Java 6, ANT 1.8.2) What version of ANT are you using? – Mads Hansen Apr 01 '11 at 22:20
  • I'm using Ant version 1.8.0. I tried what Leigh said below and it did speed up the process but only for the first transform. Same lag happens for the second transform, and it takes 1 min and 48 seconds. Which is unacceptable time for the script to execute. – Casey Jordan Apr 02 '11 at 20:12
  • What I don't understand is that the same transform is literally sub 10ms to do in oXygen. – Casey Jordan Apr 02 '11 at 20:24

1 Answers1

1

What I found was killing my performance, was loading the DTD definitions over the web.

I created an empty .dtd file, and referred the DTD public ID's to it using an ant xmlcatalog, like this (inside my <xslt/> task):

<xmlcatalog>
  <dtd publicid="-//W3C//DTD XHTML 1.0 Transitional//EN" location="empty.dtd"/>
<xmlcatalog>

This took build times down from 22 minutes (many documents) to 3 seconds!

Bob Kerns
  • 1,767
  • 1
  • 16
  • 14