Hello all,
I am using .NET XSLT to transform an XML into another XML file. All
this is fine with small files, but when tested with big files (30MB) it
is taking between 1hr-2hrs to just transform the file.
Here is the code snippet:
XPathDocument xdoc = new XPathDocument(fs);
XPathNavigator nav = xdoc.CreateNavigator();
xslt.Transform(nav, null, strWriter, null);
I read in this forum (Oleg T) that using keys will speed up the
transformation. Apart from this the other suggestion was to use MSXML
which is much faster (Which I cannot use). Below are the Input XML,
XSLT and a sample of the Output XML. I truncated part of Input and
Output XML for clarity purposes. Can someone please give me suggestions
on how to use Keys in the XSLT or any other method of Optimizing this
tranformation? Any ideas will be really helpful.
Input XML:
---------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<POC xmlns="www.poctest.com">
<Cars>
<West>
<row>
<Dept>6000</Dept>
<DeptDir>A</DeptDir>
<Adny>apart</Adny>
<Closd>10/20/2003</Closd>
<Open>2/15/1996</Open>
<CarType>0</CarType>
<Desc1>Sum 1 blew it</Desc1>
<FileNumber>12352</FileNumber>
<DevAmt>0.00</DevAmt>
<DevDate />
<StageAddr1>W. 117TH ST.</StageAddr1>
<StageCity>ALL</StageCity>
<StageCnty>County</StageCnty>
<StageCode>RRS</StageCode>
<StageSt>OH</StageSt>
<SOrderNo>656565</SOrderNo>
<SPolDate>10/4/1994</SPolDate>
<Staff>WXW</Staff>
<StBrdCompl />
<StBrdNumbr />
<BootComp>N</BootComp>
<BootIns>Y</BootIns>
</row>
<row>
<Dept>6001</Dept>
<DeptDir>A</DeptDir>
<Adny>apart</Adny>
<Closd>10/20/2003</Closd>
<Open>2/15/1996</Open>
<CarType>0</CarType>
<Desc1>Sum 1 blew it</Desc1>
<FileNumber>12352</FileNumber>
<DevAmt>0.00</DevAmt>
<DevDate />
<StageAddr1>W. 117TH ST.</StageAddr1>
<StageCity>ALL</StageCity>
<StageCnty>County</StageCnty>
<StageCode>RRS</StageCode>
<StageSt>OH</StageSt>
<SOrderNo>656565</SOrderNo>
<SPolDate>10/4/1994</SPolDate>
<Staff>WXW</Staff>
<StBrdCompl />
<StBrdNumbr />
<BootComp>N</BootComp>
<BootIns>Y</BootIns>
</row>
</West>
<South>
<row>
<Dept>7000</Dept>
<DeptDir>B</DeptDir>
<Adny>apart</Adny>
<Closd>10/20/2003</Closd>
<Open>2/15/1996</Open>
<CarType>0</CarType>
<Desc1>Sum 1 blew it</Desc1>
<FileNumber>12352</FileNumber>
<DevAmt>0.00</DevAmt>
<DevDate />
<StageAddr1>117TH ST.</StageAddr1>
<StageCity>ALL</StageCity>
<StageCnty>County</StageCnty>
<StageCode>RRS</StageCode>
<StageSt>OH</StageSt>
<SOrderNo>656ss565</SOrderNo>
<SPolDate>10/4/1994</SPolDate>
<Staff>WXW</Staff>
<StBrdCompl />
<StBrdNumbr />
<BootComp>N</BootComp>
<BootIns>Y</BootIns>
</row>
</South>
</Cars>
</POC>
---------------------------------------------------------------------------------------------------------
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:poc="www.poctest.com"
exclude-result-prefixes="poc"
version="1.0">
<xsl:output encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="poc:Cars">
<Fields>
<xsl:apply-templates/>
</Fields>
</xsl:template>
<xsl:template match="poc:row">
<Record>
<LineNumber><xsl:number level="any" /></LineNumber>
<AreaPath>
<xsl:for-each select="(ancestor::*)">
<xsl:value-of select="local-name()"/>
<xsl:if test="not(position()=last())">\</xsl:if>
</xsl:for-each>
</AreaPath>
<xsl:apply-templates select="node()|@*" />
<xsl:if test="normalize-space(.//poc:Closd)=''">
<Status>O</Status>
</xsl:if>
<xsl:if test="normalize-space(.//poc:Closd)!=''">
<Status>C</Status>
</xsl:if>
</Record>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="poc:POC">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="poc:West">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="poc:East">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="poc:South">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="poc:North">
<xsl:apply-templates/>
</xsl:template>
<!-- Replace Element Adny with TermPost -->
<xsl:template match="poc:Adny">
<TermPost>
<xsl:apply-templates select="@* | node()" />
</TermPost>
</xsl:template>
<!-- Replace Element FileNumber with TyreNumber -->
<xsl:template match="poc:FileNumber">
<TyreNumber>
<xsl:apply-templates select="@* | node()" />
</TyreNumber>
</xsl:template>
<!-- Replace Element Staff with Bat -->
<xsl:template match="poc:Staff">
<Bat>
<xsl:apply-templates select="@* | node()" />
</Bat>
</xsl:template>
<!-- Replace Element Open with Date -->
<xsl:template match="poc:Open">
<Date>
<xsl:apply-templates select="@* | node()" />
</Date>
</xsl:template>
<!-- Replace Element Closd with Closed -->
<xsl:template match="poc:Closd">
<Closed>
<xsl:apply-templates select="@* | node()" />
</Closed>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------------------------------------------
Output XML
<?xml version="1.0" encoding="utf-8" ?>
<Fields>
<Record>
<LineNumber>1</LineNumber>
<AreaPath>POC\Cars\West</AreaPath>
<Dept>6000</Dept>
<DeptDir>A</DeptDir>
<TermPost>apart</TermPost>
<Closed>10/20/2003</Closed>
<Date>2/15/1996</Date>
<CarType>0</CarType>
<Desc1>Sum 1 blew it</Desc1>
<TyreNumber>12352</TyreNumber>
<DevAmt>0.00</DevAmt>
<DevDate />
<StageAddr1>W. 117TH ST.</StageAddr1>
<StageCity>ALL</StageCity>
<StageCnty>County</StageCnty>
<StageCode>RRS</StageCode>
<StageSt>OH</StageSt>
<SOrderNo>656565</SOrderNo>
<SPolDate>10/4/1994</SPolDate>
<Bat>WXW</Bat>
<StBrdCompl />
<StBrdNumbr />
<BootComp>N</BootComp>
<BootIns>Y</BootIns>
<Status>O</Status>
</Record>
</Fields>