Subject: [xsl] How to improve the performance where a key element used in multiple document()'s From: "Yang" <sfyang@xxxxxxxxxxxxx> Date: Fri, 22 Jun 2001 16:39:35 +0800 |
Hi, I am working on with two large set of xml documents main.xml contains 1800 elements and detail.xml 5800 elements. A key element is used for both of documents for different functions. The key task is list out the related detailed data from detail.xml for each orderno in main.xml. My plot is as following: 1. Use document() function to access the xml and use the RTF to store normalized values for both xml. 2 Use Muenchian method and the key element <xsl:key name="TransNo" match="z:row" use="@OrderNo" /> to generate an unique set of data for OrderNo from main.xml. 3 Search for the associated data from detail.xml for each OrderNo using steps as: 3.1 Create the RTF for each OrderNO, which will update the key element content. 3.2 Use key('TransNo',$thisNo) to pick up the information from RTF. I get solutions all right but the performance is terrible, especially when comparing it with behaviour of the following approach; 1. using detail.xml only to work on the unique set of orderNo. 2. using key function to access to the related values. No updating key element is used. Then I find the performance is improved substantially. Therefore I guess it is still a large room to speed up the performance for what I intend to do in the first place. Would someone give me some help? Much thanks in advance. Sun-Fu Yang sfyang@xxxxxxxxxxxxx The above described xsl file list below fyi. *** xsl-a - using one key element for two xml documents, poor performance ** <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="rs z msxsl"> <xsl:output method="xml" indent="yes"/> <!-- the following key element is used for main.xml and detail.xml as well --> <xsl:key name="TransNo" match="z:row" use="@OrderNo" /> <xsl:variable name="xmla" select="'main.xml'"/> <xsl:variable name="xmlb" select="'detail.xml'"/> <!-- get the unique set of TransNo --> <xsl:variable name="sourceLine"> <xsl:call-template name="normalized-rs"> <xsl:with-param name="xmlfile" select="$xmla"/> </xsl:call-template> </xsl:variable> <xsl:variable name="originalDoc" select="msxsl:node-set($sourceLine)" /> <xsl:variable name="MSource" select="$originalDoc/z:row"/> <xsl:variable name="TransNoheading" select="$MSource[generate-id(.)=generate-id(key('TransNo',@OrderNo)[1])]"/> <!-- define the TransOrderDtl node-set --> <xsl:variable name="sourceLineDtl"> <xsl:call-template name="normalized-rs"> <xsl:with-param name="xmlfile" select="$xmlb"/> </xsl:call-template> </xsl:variable> <xsl:variable name="originalDoc2" select="msxsl:node-set($sourceLineDtl)" /> <xsl:variable name="TransDtl" select="$originalDoc2/z:row" /> <xsl:template match="/"> <!-- sorting the TransNo and copy of attribute contents --> <xsl:variable name="TransNo"> <xsl:for-each select="$TransNoheading"> <xsl:sort select="@OrderNo"/> <scode><xsl:value-of select="@OrderNo"/></scode> </xsl:for-each> </xsl:variable> <xsl:variable name="allTransNo" select="msxsl:node-set($TransNo)/scode"/>' <table> <xsl:for-each select="$allTransNo"> <xsl:variable name="thisNo" select="node()"/> <!-- to get the data set and meantime upate key element --> <xsl:variable name="sourceLine2"> <xsl:copy-of select="$TransDtl[string(@OrderNo[string($thisNo)])=$thisNo]"/> </xsl:variable> <xsl:variable name="originalDoc" select="msxsl:node-set($sourceLine2)"/> <xsl:variable name="MSource" select="$originalDoc/z:row"/> <!-- pick the corresponding data from transDtl of each transno --> <xsl:for-each select="$originalDoc"> <xsl:apply-templates select="key('TransNo',$thisNo)" mode="transDtl"/> </xsl:for-each> <!-- I wonder the above 10 lines somehow take much computational time --> </table> </xsl:for-each> </xsl:template> <xsl:template match="z:row" mode="transno"> ... </xsl:template> <xsl:template match="z:row" mode="transDtl"> ... </xsl:template> </xsl:stylesheet> ** xsl-b the following xsl gets much better performance ** <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="rs z msxsl"> <xsl:output method="xml" indent="yes"/> <xsl:key name="TransNo" match="z:row" use="@*" /> <xsl:include href="normalized-rs.xsl"/> <xsl:variable name="xmla" select="'detail.xml'"/> <xsl:variable name="sourceLine"> <xsl:call-template name="normalized-rs"> <xsl:with-param name="xmlfile" select="$xmla"/> </xsl:call-template> </xsl:variable> <xsl:variable name="originalDoc" select="msxsl:node-set($sourceLine)" /> <xsl:variable name="MSource" select="$originalDoc/z:row"/> <xsl:variable name="TransNoheading" select="$MSource[generate-id(.)=generate-id(key('TransNo',@OrderNo)[1])]"/> <xsl:template match="/"> <xsl:variable name="TransNox"> <xsl:for-each select="$TransNoheading"> <xsl:sort select="@OrderNo"/> <z:row> <xsl:copy-of select="@*"/></z:row> </xsl:for-each> </xsl:variable> <xsl:for-each select="$TransNoheading"> <xsl:variable name="thisNo" select="@OrderNo"/> <xsl:value-of select="$thisNo"/> <xsl:apply-templates select="key('TransNo',$thisNo)" mode="transDtl"/> </xsl:for-each> </xsl:template> <xsl:template match="z:row" mode="transno"> .. </xsl:template> <xsl:template match="z:row" mode="transDtl"> .. </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
AW: [xsl] WG: How to reorder an XML, Griebel, Peer | Thread | Re: [xsl] How to improve the perfor, Jeni Tennison |
RE: [xsl] Is this an encoding issue, Michael Kay | Date | [xsl] RE: Fatal error reported by X, Michael Kay |
Month |