Archive for August, 2009

Giving saxon-xslt large amounts of memory

August 4, 2009

I was running the following XSLT 2.0 script:


</span>
<?xml version="1.0" encoding="UTF-8"?>  
<xsl:stylesheet version="2.0" 
                                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
                                xmlns:tei="http://www.tei-c.org/ns/1.0" 
                                xmlns:saxon="http://saxon.sf.net/" 
                                exclude-result-prefixes="tei">  
 <xsl:variable name="files" select="collection('./tei/?select=*.xml')"/>  

    <xsl:template match="/">  
       <names>
          <xsl:for-each select="for $x in $files return saxon:discard-document($x)">  
             <xsl:for-each select=".//tei:name">
                <xsl:text>
</xsl:text>
                <name>  
                   <xsl:value-of select=".//text()"/>  
                </name>  
                <xsl:text>
</xsl:text>
            </xsl:for-each>  
          </xsl:for-each>  
       </names>
    </xsl:template>  
</xsl:stylesheet>
<span style="font-size: x-small;"> 

It just iterates over all files and all names within the file and outputs a list of the text with the names with lots of whitespace (I detest XML all scrunched up without whitespace).

Alas it was giving me the error “Exception in thread “main” java.lang.OutOfMemoryError: Java heap space” errors, so I knew I had to give it more. The trick turned out to be changing the command line from:

saxonb-xslt -ext:on get-all-names.xsl get-all-names.xsl

to:

java -Xmx8000M -jar /usr/share/java/openoffice/saxon9.jar  -ext:on get-all-names.xsl get-all-names.xsl

This, of course, is on a 64bit machine with 8G of RAM, so Java can stretch out it’s legs into that space. Worked a treat.

Advertisements