Nice XSL trick to remove last comma from an incoming CSV string


I had a case recently where I had to remove a trailing comma from an incoming value within a feed. The trimming had to be done in XSL and the string was not being assembled within a for-each loop, so I needed a simple way to remove the last ‘,’. Here’s two lines that do the trick. I posted this because I didn’t find it via Google – what I found were solutions to ‘not’ add a comma after the last concatenation within a for-each.

<xsl:variable name="len" select="string-length(normalize-space(atom:feed/atom:entry/atom:content/atom:properties/atom:MyCommaSeparatedString))-1"/>
<xsl:value-of select="substring(atom:feed/atom:entry/atom:content/atom:properties/atom:MyCommaSeparatedString, 1, $len)"/>
Advertisements

About generation12

I am a SharePoint/.NET consultant in the twin cities.
This entry was posted in atom, Miscellaneous, xsl. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s