|
Subject: [xsl] Performance Problem Transforming Large Document From: "Schwartz, Rechell R, ALABS" <rrschwartz@xxxxxxx> Date: Wed, 18 Jun 2003 12:40:41 -0500 |
All,
I have an application where I transform an XML string into an XML document (which contains HTML) , and then transform the document to an HTML file containing special styling elements (alternate color rows), which I send directly to the browser.
The performance has been fine up until recently, when I encountered a very large XML file. Following is the code used for the transformations, and where the performance bottleneck occurred. Below the code, I have included the text from format.xsl, the stylesheet used in the bottlenecked transaction. Any suggestions on how to improve performance would be greatly appreciated. For a large file, it seems to be taking several minutes for the second transformation to take place.
Thanks in advance,
Rechell Schwartz
String flashText = sb.toString();
if (flashText == null) flashText = "";
String noflashText = "*** No flashes found
TransformerFactory tFactory = TransformerFactory.newInstance();
String xsl = "/stylesheets/data.xsl";
Transformer transformer = tFactory.newTransformer(new StreamSource(getClass().getResourceAsStream(xsl)));
transformer.setParameter("flash", flashText);
transformer.setParameter("noflash", noflashText);
String site_name = "".equals(hand.site_name) ? "N/A" : hand.site_name;
transformer.setParameter("sitename", site_name);
DOMResult domResult = new DOMResult();
transformer.transform(new StreamSource(new StringReader(hand.detailresult)), domResult);
Document document =(Document)domResult.getNode();
xsl = "/stylesheets/format.xsl";
transformer = tFactory.newTransformer(new StreamSource(getClass().getResourceAsStream(xsl)));
/** There is a huge bottleneck right here when the original XML file is very large
transformer.transform(new DOMSource(document), new StreamResult(out));
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Text of format.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:template match="node()|@*"> <!--identity transform-->
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="table/tr[td[not(a) and not(@class)]]">
<xsl:copy>
<xsl:choose>
<xsl:when test="count( preceding-sibling::tr[td[not(a) and
not(@class)]] ) mod 2 = 1">
<xsl:for-each select="td[1]">
<td class="evenMedium" width="35%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
<xsl:for-each select="td[2]">
<td class="evenMedium" width="65%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="td[1]">
<td class="oddMedium" width="35%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
<xsl:for-each select="td[2]">
<td class="oddMedium" width="65%">
<xsl:apply-templates select="node()|@*"/>
</td>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Unicode, Mike Brown | Thread | [xsl] number + document, abbouh |
| RE: [xsl] grouping by unique..., Fei Zheng | Date | Re: [xsl] Inserting global paramete, David Carlisle |
| Month |