[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Optimizing a XSLT

Subject: Optimizing a XSLT
From: "Eric Barre" <ericbarre@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 14 Apr 2003 11:01:33 -0700
disable output escaping yes xslt
Hi,
 
I wrote a XSL file to transform a XML file to another XML file,
everything works fine on small file but eventually I will be using it
against large XML file (over 1mg).
When I run it against such a large file it takes for ever to return, I
mean I have to kill it after running for an hour.
Is there a way to optimize the XSL that I have to make it perform
better?
Here is the 'input' XML: 
<CSVFile>
 <ROW>
  <unit>DOUG_1</unit>
  <schedule>101</schedule>
  <textdate>2003-04-09</textdate>
  <texthour>18</texthour>
  <mw>999999</mw>
  <price>16.09</price>
  <ScheduleType>Cost</ScheduleType>
  <MarketAvailability>RealTime</MarketAvailability>
 </ROW>
 <ROW>
  <unit>DOUG_1</unit>
  <schedule>199</schedule>
  <textdate>2003-04-09</textdate>
  <texthour>18</texthour>
  <mw>999999</mw>
  <price>0.00</price>
  <ScheduleType>Cost</ScheduleType>
  <MarketAvailability>RealTime</MarketAvailability>
 </ROW>
 <ROW>
  <unit>ERIC_1</unit>
  <schedule>201</schedule>
  <textdate>2003-04-09</textdate>
  <texthour>18</texthour>
  <mw>0</mw>
  <price>10.79</price>
  <ScheduleType>Cost</ScheduleType>
  <MarketAvailability>RealTime</MarketAvailability>
 </ROW>
 <ROW>
  <unit>ERIC_1</unit>
  <schedule>201</schedule>
  <textdate>2003-04-09</textdate>
  <texthour>18</texthour>
  <mw>18</mw>
  <price>21.59</price>
  <ScheduleType>Cost</ScheduleType>
  <MarketAvailability>RealTime</MarketAvailability>
 </ROW>
</CSVFile> 
 
The XSL:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" indent="no"/>
 <xsl:template match="/">
  <SubmitRequest>
   <xsl:call-template name="RowProcess"/>
   <xsl:text
disable-output-escaping="yes">&lt;/PriceCurvehourly&gt;</xsl:text>
   <xsl:text
disable-output-escaping="yes">&lt;/OfferPriceCurve&gt;</xsl:text>
   <xsl:text
disable-output-escaping="yes">&lt;ScheduleType&gt;</xsl:text>
    <xsl:value-of select="CSVFile/ROW/ScheduleType"/>
   <xsl:text
disable-output-escaping="yes">&lt;/ScheduleType&gt;</xsl:text>
   <xsl:text
disable-output-escaping="yes">&lt;MarketAvailability&gt;</xsl:text>
    <xsl:value-of select="CSVFile/ROW/MarketAvailability"/>
   <xsl:text
disable-output-escaping="yes">&lt;/MarketAvailability&gt;</xsl:text>

   <xsl:text
disable-output-escaping="yes">&lt;/UnitScheduleOffer&gt;</xsl:text>   
  </SubmitRequest>
 </xsl:template>
 <!--Processing-->
 <xsl:template name="RowProcess">
  <xsl:for-each select="/CSVFile/ROW">
   <xsl:call-template name="UnitProcess"/>
  </xsl:for-each>  
 </xsl:template>
 <xsl:template name="UnitProcess">
  <xsl:call-template name="unit"/>
 </xsl:template>
 <xsl:template name="unit">
   <xsl:choose>
    <xsl:when test="unit=preceding::unit">
     <xsl:choose>
      <xsl:when test="schedule=preceding::schedule">
       <xsl:call-template name="PricePointProcess"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:call-template name="NewUnit"/> 
       <xsl:call-template name="PricePointProcess"/>       
      </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
     <xsl:call-template name="NewUnit"/>     
     <xsl:call-template name="PricePointProcess"/>
    </xsl:otherwise>
   </xsl:choose>   
 </xsl:template>
 <xsl:template name="NewUnit">
  <xsl:choose>
   <xsl:when test="position()!=1">    
    <xsl:text
disable-output-escaping="yes">&lt;/PriceCurvehourly&gt;</xsl:text>
    <xsl:text
disable-output-escaping="yes">&lt;/OfferPriceCurve&gt;</xsl:text>
    <xsl:text
disable-output-escaping="yes">&lt;ScheduleType&gt;</xsl:text>
     <xsl:value-of select="ScheduleType"/>
    <xsl:text
disable-output-escaping="yes">&lt;/ScheduleType&gt;</xsl:text>
    <xsl:text
disable-output-escaping="yes">&lt;MarketAvailability&gt;</xsl:text>
     <xsl:value-of select="MarketAvailability"/>
    <xsl:text
disable-output-escaping="yes">&lt;/MarketAvailability&gt;</xsl:text>

    <xsl:text
disable-output-escaping="yes">&lt;/UnitScheduleOffer&gt;</xsl:text>     
   </xsl:when>
  </xsl:choose>     
   <xsl:text disable-output-escaping="yes">&lt;UnitScheduleOffer
unit="</xsl:text>
   <xsl:value-of select="unit"/>
   <xsl:text disable-output-escaping="yes">" schedule="</xsl:text>
   <xsl:value-of select="schedule"/>
   <xsl:text disable-output-escaping="yes">" day="</xsl:text>
   <xsl:value-of select="textdate"/>
   <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
   <xsl:text
disable-output-escaping="yes">&lt;OfferPriceCurve&gt;</xsl:text>   
   <xsl:text disable-output-escaping="yes">&lt;PriceCurvehourly
hour="</xsl:text>
    <xsl:value-of select="texthour"/>
   <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
 </xsl:template>
 <xsl:template name="PricePointProcess">
  <xsl:text disable-output-escaping="yes">&lt;PricePoint MW="</xsl:text>
   <xsl:value-of select="mw"/>
  <xsl:text disable-output-escaping="yes">" price="</xsl:text>
   <xsl:value-of select="price"/>
  <xsl:text disable-output-escaping="yes">"/&gt;</xsl:text>
 </xsl:template>
</xsl:stylesheet>

 
and the expected output:
 
<?xml version="1.0" encoding="UTF-8"?>
<SubmitRequest>
 <UnitScheduleOffer unit="DOUG_1" schedule="101" day="2003-04-09">
  <OfferPriceCurve>
   <PriceCurvehourly hour="18">
    <PricePoint MW="0" price="8.04"/>
    <PricePoint MW="68" price="16.09"/>
    <PricePoint MW="999999" price="16.09"/>
   </PriceCurvehourly>
  </OfferPriceCurve>
  <ScheduleType>Cost</ScheduleType>
  <MarketAvailability>RealTime</MarketAvailability>
 </UnitScheduleOffer>
 <UnitScheduleOffer unit="DOUG_1" schedule="199" day="2003-04-09">
  <OfferPriceCurve>
   <PriceCurvehourly hour="18">
    <PricePoint MW="999999" price="0.00"/>
   </PriceCurvehourly>
  </OfferPriceCurve>
  <ScheduleType>Cost</ScheduleType>
  <MarketAvailability>RealTime</MarketAvailability>
 </UnitScheduleOffer>
 <UnitScheduleOffer unit="ERIC_1" schedule="201" day="2003-04-09">
  <OfferPriceCurve>
   <PriceCurvehourly hour="18">
    <PricePoint MW="0" price="10.79"/>
    <PricePoint MW="18" price="21.59"/>
    <PricePoint MW="999999" price="21.59"/>
   </PriceCurvehourly>
  </OfferPriceCurve>
  <ScheduleType>Cost</ScheduleType>
  <MarketAvailability>RealTime</MarketAvailability>
 </UnitScheduleOffer>
</SubmitRequest> 
 
After reading some posting I tried to stay away from the <xsl:for-each>
as much as possible as well as using variables and parameters.
If anyone could let me know a way to optimize this I would appreciate
it. 
 
 
Thanks,
Eric Barre
 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.