[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Basic string parsing/splitting question.

Subject: RE: Basic string parsing/splitting question.
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Thu, 10 Jun 2004 17:20:21 -0400
string parsing
> From: Stoaks, Max [mailto:Stoaks_Max@xxxxxxxxxxxxxxxx] 
> 
> I have a comma delimited list of tokens in a string that I 
> want to get the first three from (if there are more than 
> three). Else just the first one or two.
> 
> I.e. Given this string:
> "Dogs, Big Sheep, Little Mice, Ants, Pelicans"
> 
> I'd like the result to be:
> "Dogs, Big Sheep, Little Mice ..." 
> 
> Given:
> "Dogs, Big Sheep, Little Mice"
> It should just say:
> "Dogs, Big Sheep, Little Mice"
> 
> Ditto for shorter ones.

This is a FAQ - see, for example, Dave Pawson's FAQ which has a similar
example at

http://www.dpawson.co.uk/xsl/sect2/N7240.html#d8763e280

You can do this fine in xslt 1.0 without going to exslt.  Generally, you
use a recursive template.  You pass the string in to the named template
as a parameter.  You test for the presence of a comma, and break the
string into a "first" and a "last" part.  Output the first part.  If
there is a last part, pass it to the same template. Otherwise output
your terminal string, which in your case will be "...". You may need a
bit more logic to output a comma after each bit, depending on whether
you keep the comma when you split the string.

Cheers,

Tom P

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.