Guest Rob HCS Posted November 1, 2010 Share Posted November 1, 2010 Hi all,We're using XSL to transform one format of XML into another format of XML. We having been doing this for years but have only just started doing some benchmarking. It turns out that the XSL that we're using is actually slower than modifying the XML via DOM in c#. This makes no sense so I'm assuming that the XSL that we are using is not efficient. This is representative of our input XML: <Quote> <Plans> <Plan> <PlanID>36902</PlanID> <BenefitA>Fee B</BenefitA> <Cost>100.2000</Cost> </Plan> <Plan> <PlanID>36903</PlanID> <BenefitA>Fee A</BenefitA> <Cost>100.2000</Cost> </Plan> <Employee> <PlanID>36902</PlanID> <EmployeeId>1</EmployeeId> <Rate>33.4000</Rate> </Employee> <Employee> <PlanID>36902</PlanID> <EmployeeId>2</EmployeeId> <Rate>33.4000</Rate> </Employee> <Employee> <PlanID>36903</PlanID> <EmployeeId>1</EmployeeId> <Rate>33.4000</Rate> </Employee> <Employee> <PlanID>36903</PlanID> <EmployeeId>2</EmployeeId> <Rate>33.4000</Rate> </Employee> </Plans></Quote> This is representative of our existing XSL: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/> <xsl:template match="/"> <Quote> <Plans> <xsl:for-each select="Quote/Plans/Plan"> <Plan> <xsl:variable name="planid" select="PlanID"/> <PlanID> <xsl:value-of select="PlanID"/> </PlanID> <Cost> <xsl:value-of select="Cost"/> </Cost> <Benefits> <BenefitA> <xsl:value-of select="BenefitA"/> </BenefitA> </Benefits> <Employees> <xsl:for-each select="/Quote/Plans/Employee[PlanID=$planid]"> <Employee> <xsl:attribute name="EmployeeId"><xsl:value-of select="EmployeeId"/></xsl:attribute> <Rate> <xsl:value-of select="Rate"/> </Rate> </Employee> </xsl:for-each> </Employees> </Plan> </xsl:for-each> </Plans> </Quote> </xsl:template></xsl:stylesheet> Any suggestions on how we can improve the performance of this process would be greatly appreciated!/Rob Link to comment Share on other sites More sharing options...
Martin Honnen Posted November 1, 2010 Share Posted November 1, 2010 Using keys is a "key" to better performance: <!-- this is a child of xsl:stylesheet --><xsl:key name="k1" match="Employee" use="PlanID"/> then replace <xsl:for-each select="/Quote/Plans/Employee[PlanID=$planid]"> with <xsl:for-each select="key('k1', $planid)"> That is something you can do within your XSLT stylesheet. Other improvements depend on the XSLT processor and its API you use, for instance for Saxon Michael Kay always points out that you should let Saxon use its own tree model whenever possible instead of building and passing in a DOM tree yourself in your code. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.