How to split a string with XSL

I needed to break a string like this “Hot Waffles,Fresh Fruits,Pastries,Bagels,Cereals,Muffins,Juices,Milk,Coffee” into separate XML elements. How to do it? Use a “tokenize” function!

<xsl:template name=”breakfast”>
<xsl:param name=”allItems”/>
<xsl:for-each select=”tokenize($allItems, ‘,’)”>
<item><xsl:value-of select=’.’/></item>
</xsl:for-each>
</xsl:template>

Result:

<item>Hot Waffles</item>
<item>Fresh Fruits</item>
<item>Pastries</item>
<item>Bagels</item>
<item>Cereals</item>
<item>Muffins</item>
<item>Juices</item>
<item>Milk</item>
<item>Coffee</item>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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