[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Performance problem

Subject: Performance problem
From: "ficfic m" <ficfic@xxxxxxxxxxx>
Date: Tue, 15 Feb 2005 13:32:26 +0200
xsl performance
Hi all,

Ive tried to find tips on how to improve the performance of my XSL file and so far did not find something meaningful.
The most time-consuming part in my xml is a big-list of items


<data>
	<item name=abc timestamp=2004-10-11T15:49:31>
		<bytes> 1062207488</bytes>
	</item>
<item name=efd timestamp=2004-10-13T15:44:31>
		<bytes>23457</bytes>
	</item>
....
</data>

I process the timestamp field as follow:
INPUT -> 2004-10-11T15:49:31   OUTPUT -> 2004-Oct-11 15:49:31

I process the bytes field as follow:
INPUT -> 1048576                    OUTPUT -> 1,013MB

And display it all in a table.

My xsl file:
<xsl:template match="data">
<table border="1" cellspacing="0" cellpadding="3">
	<tr>
		<th>Name</th>
		<th>Bytes</th>
		<th>Time Stamp</th>
	</tr>
	<xsl:for-each select="item">
	<tr>
	<td nowrap="1">
		<xsl:value-of select="@name"/>
	</td>
	<td>
		<xsl:choose>
		<xsl:when test="bytes">
			<xsl:call-template name="format-bytes">
				<xsl:with-param name="bytes_cnt" select="bytes"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>&#160;</xsl:text>
		</xsl:otherwise>
		</xsl:choose>
	</td>
	<td nowrap="1">
		<xsl:call-template name="format-date">
			<xsl:with-param name="date-time" select="@timestamp"/>
		</xsl:call-template>
	</td>
	</tr>
	</xsl:for-each>
	</table>
</xsl:template>

<!-- prints-out bytes count -->
<xsl:variable name="Mega" select="1024 * 1024"/>
<xsl:variable name="Giga" select="1024 * $Mega"/>

<xsl:template name="format-bytes">
<xsl:param name="cnt_bytes" select="."/>
<xsl:choose>
<xsl:when test="$ cnt_bytes &lt; 1024"><xsl:value-of select="format-number($cnt_bytes, '#,##0')"/>Bytes</xsl:when>
<xsl:when test="$ cnt_bytes &lt; $Mega"><xsl:value-of select="format-number($cnt_bytes div 1024, '#,###.##')"/>KB</xsl:when>
<xsl:when test="$ cnt_bytes &lt; $Giga"><xsl:value-of select="format-number($cnt_bytes div $Mega, '#,###.##')"/>MB</xsl:when>
<xsl:when test="$ cnt_bytes"><xsl:value-of select="format-number($cnt_bytes div $Giga, '#,###.##')"/>GB</xsl:when>
<xsl:otherwise><xsl:text>&#160;</xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:template>


<!-- prints-out timestamp in format : dd-mon-yy H:M:S -->

<xsl:template name="format-date">
<xsl:param name="date-time" select="."/>
<xsl:choose>
<xsl:when test="$date-time">
	<xsl:value-of select="substring($date-time, 9 ,2)"/>
	<xsl:text>-</xsl:text>
	<xsl:variable name="month" select="substring($date-time, 6 ,2)"/>
	<xsl:choose>
		<xsl:when test="$month = 1">Jan</xsl:when>
		<xsl:when test="$month = 2">Feb</xsl:when>
		<xsl:when test="$month = 3">Mar</xsl:when>
		<xsl:when test="$month = 4">Apr</xsl:when>
		<xsl:when test="$month = 5">May</xsl:when>
		<xsl:when test="$month = 6">Jun</xsl:when>
		<xsl:when test="$month = 7">Jul</xsl:when>
		<xsl:when test="$month = 8">Aug</xsl:when>
		<xsl:when test="$month = 9">Sen</xsl:when>
		<xsl:when test="$month = 10">Oct</xsl:when>
		<xsl:when test="$month = 11">Nov</xsl:when>
		<xsl:when test="$month = 12">Dec</xsl:when>
	</xsl:choose>
	<xsl:text>-</xsl:text>
	<xsl:value-of select="substring($date-time, 3 ,2)"/>
	<xsl:text> </xsl:text>
	<xsl:value-of select="substring($date-time, 12 ,8)"/>
</xsl:when>
<xsl:otherwise>
	<xsl:text>&#160;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

1. How can I improve this code?
2. Should I use the <for-each> or <xsl:template match=item> ?
3. In 1/3 of the times the bytes element doesnt appears in the xml file, that is why I put a check before calling the "format-bytes" template, do you think is it best to always call the template and then check inside of the template if it exists ?
4. Do you think I should use xsl:template or xsl:function to format my timestamp/bytes ?


Best Regards,
ficfic

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.