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 October 14th, 2009, 11:57 AM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default Alternative to last()function

As the title of the post indicates, can someone please suggest an alternative to the last()function. I'm basically looking for something that'll returns an integer representing the number of items in the current context. I just want to use something other than the last function b/c of performance issues.
 
Old October 14th, 2009, 12:04 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't think there is real alternative.
XPath has the count function so you could try to count the number of nodes you want to process.
And XSLT has the xsl:number element that also counts some nodes.
But none of that is a replacement for last() in my view.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 14th, 2009, 12:06 PM
Authorized User
 
Join Date: Sep 2008
Posts: 37
Thanks: 5
Thanked 0 Times in 0 Posts
Default

So there's really nothing other than something like count($variable)?
 
Old October 14th, 2009, 12:12 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I don't really know why last() should pose any performance issues, or rather I can't think of any alternative that is going to be more performant. Performance issues depend greatly on what processor you are using and how you have structured your XSLT as well, so telling us a bit more detail might help.

One alternative that springs to mind is to create a xsl:variable outside of the context and use the count() method. As I said, I can't imagine that this would be faster though.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 14th, 2009, 12:38 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There may be ways of writing your code that are faster under some circumstances on some processors. But there won't be any alternative that is always faster on every processor. So you need to say more about what your requirements are, what technology you ar using, and what the symptoms of your performance trouble are.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternative to Codeplot? pfloyd BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 21 June 5th, 2011 03:57 AM
Alternative to BOOKMARKS Shiamak Word VBA 2 October 31st, 2008 04:04 PM
Image Alternative TSEROOGY Javascript 5 December 6th, 2004 10:39 AM
alternative to MemCpy sanjaykabra82 VS.NET 2002/2003 1 September 17th, 2004 12:10 AM





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