How do I truncate Elements from xmlDoc?

I have an XML file that looks like:
<?XML>
<MainElement>
<ChildElement>
<!-- Record 1 -->
</ChildElement>
...
<ChildElement>
<!-- Record N -->
</ChildElement>
...
<ChildElement>
<!-- Record M -->
</ChildElement>
</MainElement>

The "ChildElement" can have more than 5000 records. In order to transform the records through XSLT, it takes very long time for that kind of records. What I found is that by reducing the records before XSLT, the transformation time can be reduced largely even we have to do XSLT multiple times.
Is there a better way to deal with this kind of large record transformation? Or this is the only way to deal with it? Thanks.

If this is the only way, I'm facing the problem on how to truncate the records by using xmlDoc? The "removeChild" call seems to alternate original xmlDoc.

Thanks

William
[1023 byte] By [wtang] at [2007-11-18 16:58:35]
# 1 Re: How do I truncate Elements from xmlDoc?
If I understand you correctly, your execution time is growing faster than the size of your dataset. Which ofcourse means that some nonlinear processing is taking place.

Depending on your stylesheet and and xslt engine, you might be able to optimize your stylesheet, to get back to linear execution time.
The trick is ofcourse to avoid things like sorting, and things like looking at the sibling axis.

I just did a quick test, using Xalan-J, with a simple stylesheet and two datasets containing 20000 and 40000 elements, execution time was 6.9 secs for the dataset containing 20000 records and 7.9 for the dataset containing 40000 records (Obviosly part of this time is spent stating java and compiling the stylesheet)
khp at 2007-11-10 3:28:25 >
# 2 Re: How do I truncate Elements from xmlDoc?
You are right! My xslt is looking at the sibling axis which slows down dramatically the process time.

I have another question related to the xslt

<xsl:template match="bookstore">

<xsl:variable name="reAction" select = "1"/>

<xsl:apply-templates select="book"/>

</xsl:template>

<xsl:template match="book">

how can I use the variable reAction here??

</xsl:template>
wtang at 2007-11-10 3:29:17 >
# 3 Re: How do I truncate Elements from xmlDoc?
Something like.

<xsl:template match="bookstore">

<xsl:variable name="reAction" select = "1"/>
<xsl:apply-templates select="book">
<xsl:with-param name="rA">
<xsl:value-of select="$reAction"/>
</xsl:with-param>
</xsl:apply-templates>

</xsl:template>

<xsl:template match="book">
<xsl:param name="rA"/>
how can I use the variable reAction here??
<xsl:value-of select="$rA"/>
</xsl:template>
khp at 2007-11-10 3:30:26 >
# 4 Re: How do I truncate Elements from xmlDoc?
Thanks for the prompt reply.

</xsl:template>

<xsl:template match="book">
<xsl:param name="rA"/>
<xsl:value-of select="$rA"/>

I want to test variable rA by adding two line code down here, however, I got "can not use result tree fragment error." What is wrong?

<xsl:if test="$rA[.=1]">
</xsl:if>

</xsl:template>
wtang at 2007-11-10 3:31:20 >
# 5 Re: How do I truncate Elements from xmlDoc?
The problem is that the $rA variable is a string or a number not a nodeset.
The xsl:if should be <xsl:if test="$rA=1">
khp at 2007-11-10 3:32:25 >