Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transform Optimization 1

Status
Not open for further replies.

NBartomeli

Programmer
Jul 1, 2003
111
US
Are there any good resouces available which explain what steps can be taken to optimize XSLT sheets so transformations run faster? I am transforming an XML document using .NET and on large datasets (90,000 + records in one case) the transform takes upwords of 4 minutes.

I am fairly new to this, just looking for resources or advice (please do not tell me to work with smaller datasets, that is not an option)

Thanks in advance
 
I don't know of any such resources. If you post your code, we could make some suggestions.

Make sure your xpaths are not traversing any more node that is absolutely necessary. For example, avoid use of the double backslash '//' as this will search the entire nodeset.

Jon
 
I don't want to post the whole thing, since the files are fairly large, but here are a few snippits that might help. I do use '//' but since I am new to XSLT I am not sure what to substitute.

This is a sample of the XML passed to the XSLT
Code:
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
  <Report>
    <PageLevel1 diffgr:id="PageLevel11" msdata:rowOrder="0" diffgr:hasChanges="inserted" ID="2" Name="TOTAL U.S." Index="0">
      <RowLevel1 diffgr:id="RowLevel11" msdata:rowOrder="0" diffgr:hasChanges="inserted" ParentIndex="0" ID="-1" Name="" Index="0">
        <RowLevel2 diffgr:id="RowLevel21" msdata:rowOrder="0" diffgr:hasChanges="inserted" ParentIndex="0" ID="20209" Name="1 Week" Index="0">
          <ColumnLevel1 diffgr:id="ColumnLevel11" msdata:rowOrder="0" diffgr:hasChanges="inserted" ParentIndex="0" ID="103633" Name="3MU" Index="0">
            <ColumnLevel2 diffgr:id="ColumnLevel21" msdata:rowOrder="0" diffgr:hasChanges="inserted" ParentIndex="0" ID="40" Name="Volume" ColValue="218,845.00" Index="0" />
          </ColumnLevel1>
        </RowLevel2>
        <RowLevel2 diffgr:id="RowLevel22" msdata:rowOrder="1" diffgr:hasChanges="inserted" ParentIndex="0" ID="20210" Name="1 Week Ending" Index="1">
          <ColumnLevel1 diffgr:id="ColumnLevel12" msdata:rowOrder="1" diffgr:hasChanges="inserted" ParentIndex="1" ID="103633" Name="3MUS" Index="1">
            <ColumnLevel2 diffgr:id="ColumnLevel22" msdata:rowOrder="1" diffgr:hasChanges="inserted" ParentIndex="1" ID="40" Name="Volume (Pounds)" ColValue="259,294.00" Index="1" />
          </ColumnLevel1>
        </RowLevel2>

And here is a sample of the XSLT:
Code:
<xsl:when test="//PageLevel1[1]/RowLevel1[1]/RowLevel2[1]/ColumnLevel1[1]/@ID!=-1">
					<tr height="17" style='height:12.75pt'>
						<td nowrap ="1" class='xl28' width='220pt' >&nbsp;</td> <!-- first column -->
						<!-- for each ColumnLevel1 create a column to span the Column Level 2 columns -->
						<xsl:for-each select="//PageLevel1[1]/RowLevel1[1]/RowLevel2[1]/ColumnLevel1">
							<td class='xl29' nowrap="1" align='center' colspan='{$data_columns}' style="border-right:1.0pt solid black;"><xsl:value-of select="@Name"/></td>		
						</xsl:for-each>
					</tr>

Again, I am fairly new, just looking for pointers to make things faster.

Thanks in advance (again) for any help

 
As I said, when you use //, it will search the entire document to match. When you know the level you are looking at, specify it:
Code:
<xsl:when test="diffgr:diffgram/Report/PageLevel1[1]/RowLevel1[1]/RowLevel2[1]/ColumnLevel1[1]/@ID!=-1">
Also look at the underlying algorithm you are using, maybe you can improve it.
 
Just for my own personal reference:

When you use // , even if it finds the record near the top of the document, does it still continue to search the remainder of the document? Is that why it is so inefficient?

Thanks again for all of your help

-Nick
 
Yes. XPath will try to match as many nodes as it can to the query you give it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top