homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

Splitting comma separated text into divs

 9:35 am on Oct 3, 2008 (gmt 0)

Hi all,

I have an XML file which contains comma separated text within an element. How does one go about placing each of these within it's own "div"?


What I'd like to output is

<div class="c">
<div class="type">cumulus</div>
<div class="type">stratus</div>
<div class="type">nimbus</div>

The solution probably requires making use of a template, but what has thrown me off is the fact that there are only two commas, so I can't use <xsl:value-of select="substring-before(., '</div>')"/> or <xsl:value-of select="substring-after(., '<div>')"/>

Actually I could probably do something along the lines of opening a div before the XSL, then closing it after the XSL, but how do I split up the string?

[edited by: SilverLining at 9:46 am (utc) on Oct. 3, 2008]



 10:18 am on Oct 3, 2008 (gmt 0)

XSLT 2 has RegEx and tokenize. [w3schools.com]

In my case, I would probably use a PHP callout, and use a split() in a PHP script.


 10:58 am on Oct 3, 2008 (gmt 0)

Thanks, but is there any way of doing this straight in the XSL file? Our system does not support php.


 11:47 am on Oct 3, 2008 (gmt 0)

Do you guys have an XSLT 2 processor? If so, use the tokenize() XPath function. That's synonymous with the standard split() function.


 9:04 am on Oct 6, 2008 (gmt 0)

No. We use an XSLT 1 processor (Xalan).


 2:57 pm on Nov 13, 2008 (gmt 0)

If you know the definitive output is only two commas could you not put the div tags inside the element? when they are printed out they will render in divs?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved