Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2007, 10:14 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default Performance in String concatenation

Hello all!

A colleague asked me what was the best (and fastest) approach to concatenate strings between using:

<xsl:variable name="chain" select="concat('Nodename: ', xxx:Resource/@name, etc...)"/>

or this:

<xsl:variable name="chain">
  <xsl:text>Nodename: </xsl:text>
  <xsl:value-of select="xxx:Resource/@name"/>
  etc...
</xsl:variable>

Maybe someone here has done some performance testing and could enlighten me. I wonder if there's a situation where one method is better than the other...

Thanks,

Rushman

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
__________________
Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old September 27th, 2007, 10:25 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I'd guess it would depend on the implementation, but you are aware that the two operations are different.

The first will create a variable with the concatenated string, the second will create a variable consisting of two text nodes.

/- Sam Judson : Wrox Technical Editor -/
 
Old September 27th, 2007, 10:34 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Hi!

Yes I know that it isn't the same thing, but it is going to be used in a <xsl:value-of select="$chain"/> later on.

My guess is that concat() will be more efficient but, as you say, it will depend on implementation.

Maybe Mister Kay could confirm?
 
Old September 27th, 2007, 10:59 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Performance obviously depends on the product, but in this case I think it's clear cut: use the select attribute. That directly concatenates strings. The other approach creates a document node having multiple text nodes as its children, only to extract the string value of the document node when it's used as a string. One of my pet hates is

<xsl:variable name="x">
  <xsl:value-of select="some string"/>
</xsl:variable>

partly because it's three lines of code instead of one, and partly because it's three times slower.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 27th, 2007, 11:02 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Thank you Mr. Kay for your quick reply. You rule, as always...

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
String concatenation query. AjayLuthria XSLT 2 March 14th, 2007 11:55 AM
Convert NULL to String for Concatenation? Ron Howerton SQL Language 5 September 23rd, 2006 05:54 AM
string concatenation nulogix PHP How-To 1 June 24th, 2004 06:17 AM
string concatenation matt_99 Access VBA 2 January 17th, 2004 09:55 AM
T-SQL String Concatenation jaucourt SQL Language 2 January 13th, 2004 10:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.