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 November 4th, 2005, 02:43 PM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting

I am trying to display the following without a comma after the last element...how can I do this? Its been driving me mad for hours trying to figure it out!! Thanks in advance!

Code:
<xsl:choose>

  <xsl:when test="Author!=''">
    <xsl:value-of select="Author"/>
  </xsl:when>

  <xsl:otherwise>
    <xsl:value-of select="Editor"/>
    <xsl:text>, </xsl:text>

    <xsl:for-each select="Contributors/Author">
      <xsl:if test=".!=../../Editor">
        <xsl:value-of select="."/>
        <xsl:text>, </xsl:text>
      </xsl:if>
    </xsl:for-each>

  </xsl:otherwise>                     

</xsl:choose>
The section in red is place where I want to have no element after the last item. It is reading from a list of items and putting commas after them in the output...don't want a comma after the last one!
Thanks again :)

 
Old November 4th, 2005, 03:02 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In 1.0:

<xsl:for-each select="Contributors/Author">
  <xsl:value-of select="."/>
  <xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>

In 2.0

<xsl:value-of select="Contributors/Author" separator=", "/>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 5th, 2005, 08:23 AM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mhkay thanks a million you're a life saver! Much appreciated.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell formatting Neal Excel VBA 0 May 9th, 2006 08:02 AM
String formatting MargateFan XSLT 4 May 5th, 2006 04:54 AM
Conditional Formatting Corey Access 1 November 8th, 2005 12:18 AM
formatting dates treasacrowe Classic ASP Basics 3 October 20th, 2004 06:52 PM
Formatting Ben Access 3 February 28th, 2004 05:52 AM





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