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 March 4th, 2009, 12:32 PM
Authorized User
Join Date: Sep 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nadavvin
Default How to check for last element in for each?


I want for example to print list of elements separate by comma but I don't want to print last comma.

I tried with position and last and it isn't work.

How should I prevent execute of the last loop?
Old March 4th, 2009, 12:38 PM
Friend of Wrox
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts

With XSLT 2.0 you do not even need for-each, you can simply do e.g.
<xsl:value-of select="foo" separator=","/>
With XSLT 1.0 you need e.g.
<xsl:for-each select="foo">
   <xsl:value-of select="."/>
   <xsl:if test="position() != last()">,</xsl:if>
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog

Similar Threads
Thread Thread Starter Forum Replies Last Post
check name of the current node element in xml arunagottimukkala XSLT 19 October 19th, 2007 04:44 AM
Problem -- Empty element check ! back2grave XSLT 2 July 10th, 2006 04:58 PM
Check if string is in element hykyit XSLT 3 May 1st, 2006 09:26 AM
check if element is disabled or enabled crmpicco Javascript How-To 1 November 10th, 2005 07:21 PM
check if an array element is not undefined crmpicco Javascript How-To 1 October 6th, 2005 11:40 AM

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