2

I have a lot of xml (JUnit test results) that i want to transform with Xslt 2.0.

I am currently using the net.sf.saxon.TransformerFactoryImpl to perform the transform and the fn:collection() in my xslt to search xml files. Like this :

<xsl:variable name="files" select="collection('file:///Users/admin/Documents/testxml/?select=*.xml;recurse=yes')"/>

<xsl:template match="testsuites">
 <root>
<xsl:for-each select="$files//testsuites">
     <xsl:call-template name="summary"/>
</xsl:for-each>
 </root>        
</xsl:template>

There is 2 point that cause me trouble:

  • first is the java transformer, i have to pass a xml"source" but i dont really need it because my .xsl is doing the xml searching and listing.

  • second is when i am running the transform for more than 10 (maybe 8 or 7 ) xml my JVM heap space is full. I know i can raise the heap size but i have to apply the transform throught almost 300 xml so it will no be efficient.

Any idea about what can i do to improve the number of xml i can transform?

Thanks

EDIT :

I m trying to use the saxon:discard-document() like this :

<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:saxon="http://saxon.sf.net/">
    <xsl:output method="xml" indent="yes"/>

<xsl:variable name="files" select="collection('file:///Users/admin/Documents/testxml/?select=*.xml;recurse=yes')"/>

<xsl:template match="testsuites">
 <root>
  <xsl:for-each select="for $x in ($files//testsuites)return saxon:discard-document($x)">    
   <xsl:call-template name="summary"/>
  </xsl:for-each>    
 </root>        
</xsl:template>

but I am still getting an error with my heap space. Am I doing something wrong?

1
  • Dr. Kay, the author of Saxon, actually replied below. For best results on Saxon-related questions, you might find that [email protected] is a better resource. Both Dr. Kay and Andrew Welch (the author of that blog) are active there.
    – lavinio
    Jan 20, 2011 at 20:52

2 Answers 2

4

You don't need to pass a source object to Saxon: you can start the transformation at a named template. However, this isn't supported in the JAXP API (which only recognizes XSLT 1.0) - you're best off switching to the s9api interface to take full advantage of Saxon features.

As for saxon:discard-document(), I'm not sure from following the thread how far you have got with this. I would avoid putting the set of documents in a global variable. Instead, do

<xsl:for-each select="collection(....)/saxon:discard-document(.)//testsuites">
  ...
</xsl:for-each>
3

Try using saxon:discard-document to free up memory.

See this blog post: Using collection() and saxon:discard-document() to create reports

1
  • This is the perfect function for me. Thanks a lot.
    – Theo
    Jan 20, 2011 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.