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

RE: Xsl Transform to slow (I think)

Subject: RE: Xsl Transform to slow (I think)
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 15 Jun 2004 19:49:38 +0100
xsl slow
The line that's causing the trouble is:

<xsl:value-of select="count(preceding::*[name(.)='detail'])+1"/>

This means that for each <value> element, the system has to count all the
preceding elements in the document, which gives O(n^2) performance.

Try using <xsl:number level="any"/>: there's a chance that your XSLT
processor might implement this more efficiently.

You could also rewrite the expression as count(preceding::detail)+1, but I
doubt that would make a big difference.

If all the <detail> elements are at the same level of the hierarchy, the
expression count(../preceding-sibling::detail) +
count(../../preceding-sibling::Registo/detail)+1 might be a bit faster,
though still O(n^2).

Michael Kay 

> -----Original Message-----
> From: Hélder Sousa [mailto:Helder.Sousa@xxxxxx] 
> Sent: 14 June 2004 16:18
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Xsl Transform to slow (I think)
> 
> Hi!
> 
> I have the next XML:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Registos>
> 	<Registo>
> 		<a>aaa</a>
> 		<b>bbb</a>
> 		<value>2592.19</value>
> 		<detail>
> 			<date>2003-11-20</date>
> 			<value>13196.72</value>
> 		</detail>
> 		<detail>
> 			<date>2003-11-20</date>
> 			<value>13196.72</value>
> 		</detail>
> 	</Registo>
> 	<Registo>
> 		<a>aaa</a>
> 		<b>bbb</a>
> 		<value>0.00</value>
> 		<detail>
> 			<date>2003-11-20</date>
> 			<value>13196.72</value>
> 		</detail>
> 	</Registo>
> </Registos>
> 
> In the end I want the next XML.. The rules are:
> * if value of tag "value" in "Registo" element is equal to 
> zero then that tag (<value>) must disappear
> * all tag <detail> must have an atribute "num" that is an 
> unique incremental ID.
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Registos>
> 	<Registo>
> 		<a>aaa</a>
> 		<b>bbb</a>
> 		<value>2592.19</value>
> 		<detail num="1">
> 			<date>2003-11-20</date>
> 			<value>13196.72</value>
> 		</detail>
> 		<detail num="2">
> 			<date>2003-11-20</date>
> 			<value>13196.72</value>
> 		</detail>
> 	</Registo>
> 	<Registo>
> 		<a>aaa</a>
> 		<b>bbb</a>
> 		<detail num="3">
> 			<date>2003-11-20</date>
> 			<value>13196.72</value>
> 		</detail>
> 	</Registo>
> </Registos>
> 
> I implements the follow XSL:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:output method="xml" version="1.0" encoding="UTF-8" 
> indent="yes"/>
> 	<xsl:template match="/">
> 		<Registos>
> 		<xsl:for-each select=".//Registo">
> 			<Registo>
> 				<xsl:for-each 
> select="*[name(.)!='detail']">
> 					<xsl:if test="name(.)!='value'">
> 						<xsl:copy-of 
> select="."/>
> 					</xsl:if>
> 					<xsl:if 
> test="name(.)='value' and number(.)!=0">
> 						<xsl:copy-of 
> select="."/>
> 					</xsl:if>
> 				</xsl:for-each>
> 				<xsl:for-each 
> select="*[name(.)='detail']">
> 					<detail>
> 						<xsl:attribute 
> name="num">
> 							
> <xsl:value-of select="count(preceding::*[name(.)='detail'])+1"/>
> 						</xsl:attribute>
> 						<xsl:for-each 
> select="*">
> 							
> <xsl:copy-of select="."/>
> 						</xsl:for-each>
> 					</detail>
> 				</xsl:for-each>
> 			</Registo>
> 		</xsl:for-each>
> 		</Registos>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> Although it's work, it's to slow! Can you help me to 
> performance this xsl?
> Tks :)
> 
> 
> Hélder Sousa
> 						
> 
> 
> Esta mensagem contém informação abrangida por sigilo ou 
> confidencial. Caso tenha recebido esta mensagem 
> indevidamente, queira informar de imediato o remetente e 
> proceder à destruição de todas as cópias da mesma.
>  
> This message contains information that may be privileged or 
> confidential. If you receive this message in error please 
> notify the sender immediately and delete all copies of this message.
> 
> 
> --+------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--
> 
> 


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.