Theo
Theo

Reputation: 473

Improve XSLT transformation

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:

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?

Upvotes: 2

Views: 858

Answers (2)

Michael Kay
Michael Kay

Reputation: 163595

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>

Upvotes: 4

dogbane
dogbane

Reputation: 274828

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

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

Upvotes: 3

Related Questions