Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » [SOLVED] Using XSLT to place commas between authors


[SOLVED] Using XSLT to place commas between authors

Reply
  #1 (permalink)  
Old 08-04-08, 06:23 AM
Gregoryt Gregoryt is offline
New Member
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Using XSLT to place commas between authors

CODE:

<author><strong>Author: </strong>
<xsl:for-each select="author">
<xsl:value-of select="."/><xsl:text>, </xsl:text>
</xsl:for-each>
<br/>
</author>

PROBLEM:
This code does place a comma after each author node's text data, but it does so for the last node too, resulting in an extra comma.
Is there a way to check for when at the last node and not place a comma, or is there a code for the HTML escape code for the backspace character?

USE: This is from an xsl file for a data sheet that is used to transform various types of XML documents.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-04-08, 06:42 AM
Gregoryt Gregoryt is offline
New Member
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I figured out a solution using XPath

CODE SOLUTION:
<author><strong>Author: </strong>
<xsl:for-each select="author">
<xsl:value-of select="."/>
<xsl:if test="following-sibling::author">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<br/>
</author>

EXPLANATION:
I had to use the following-sibling::author XPath axis in the <xsl:if> element as the value of the test attribute. When there is no following sibling, then no comma and space (, ) will be placed between the <xsl:text> and </xsl:text> nodes.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating Ads Help DieuxSoldat_04 PHP 25 05-10-08 07:38 PM
XSLT processor in browser or on server UnrealEd HTML/XHTML/XML 0 08-31-06 04:16 AM
Urgent.....handling dropdowns in xslt page subbukns HTML/XHTML/XML 1 05-14-06 09:01 PM
totaling numbers from a dtabase matching a personns name lppa2004 PHP 19 07-31-05 02:59 PM
Looking for tutorials/scripts or just a place to place your own? Stef Levolger General Advertisements 1 07-26-04 10:50 PM


All times are GMT -5. The time now is 10:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.