开发者

Improve XSLT transformation

开发者 https://www.devze.com 2023-02-06 06:24 出处:网络
I have a lot of xml (JUnit test results) that i want to transform with Xslt 2.0. I am currently using thenet.sf.saxon.TransformerFactoryImpl to perform the transform

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 almos开发者_StackOverflowt 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?


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>


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消