|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Basic string parsing/splitting question.
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








