Oracle SOA Suite Online Training

Interested in learning Oracle SOA Suite 12c?
Learn from the author of this blog!
A complete and comprehensive course on the #1 platform on SOA - Oracle SOA Suite

Click here to find the complete course details
Click here to check the first session on Oracle SOA Suite 12c

================================================================================================

Tokenize a CSV and do a for-each in XSLT 1.0

There are cases where you'll have a csv and need to do a for-each on each of the tokens.
For ex, a CSV stored in a DVM has to be iterated and needs to be assigned to a target for each of the token

Here is how you can tokenize

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- Here I'm hardcoding the value, but this could be from any xml where you'll give an expression instead of a value, or from a DVM -->
<xsl:variable name='csv' select="'a,b,c'"/>
<items>
<xsl:for-each select="tokenize($csv,',')">
<item>
<xsl:value-of select="."/>
</item>
</xsl:for-each>
</items>
</xsl:template>
</xsl:stylesheet>

And the result is

<?xml version="1.0" encoding="UTF-8"?>
<items>
  <item>a</item>
  <item>b</item>
  <item>c</item>
</items>

No comments:

Post a comment