cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT Mapping

Former Member
0 Kudos

Dear friends,

I am getting a comma separated string in one of the element of the incoming XML file which I need to map into separate elements in the output file. How to go about it?

E.g. <b>Input file element:</b>

<Input>One,Two,Three,Four,Five</Input>

<b>Output Required:</b>

<Output>

<First>One</First>

<Second>Two</Second>

<Third>Three</Third>

<Fourth>Four</Fourth?

<Fifth>Five</Fifth>

</Output>

Using <xsl:value-of select="//Input"/> I am getting output as:

<Output>

<First>One,Two,Three,Four,Five</First>

<Second>One,Two,Three,Four,Five</Second>

<Third>One,Two,Three,Four,Five</Third>

<Fourth>One,Two,Three,Four,Five</Fourth?

<Fifth>One,Two,Three,Four,Five</Fifth>

</Output>

How to solve this ???

Awaiting Experts reply !!!

Accepted Solutions (0)

Answers (2)

Answers (2)

RKothari
Contributor
0 Kudos

Hi Jose,

You can use the standard SubString function, if you know the Exact length of the incoming fields (comma separated) in the Input file. You have to provide the starting position and the no. of characters, of the fields as an input to the function.

Regards,

Rahul

moorthy
Active Contributor
0 Kudos

Hi,

BTW, why do u need to use XSLT Mapping ? any specific requirement?

IF so, I don;t think there is a built-in function to substring in the xslt mapping.. anyway u can check this :

http://w3schools.com/xsl/default.asp

Also if not, u can call Java functions from the XSLT mapping and u can do this very easily..

/people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners

If u don;t want to do in the XSLT mapping, then u can easily achieve it via build-in mapping functions or user defined functions in the message mapping..

Hope this helps,

Moorthy

Former Member
0 Kudos

Here functions available for XSLT mapping, see if it can help u.

fn:string-join((string,string,...),sep) Returns a string created by concatenating the string arguments and using the sep argument as the separator

Example: string-join(('We', 'are', 'having', 'fun!'), ' ')

Result: ' We are having fun! '

Example: string-join(('We', 'are', 'having', 'fun!'))

Result: 'Wearehavingfun!'

Example:string-join((), 'sep')

Result: ''

fn:substring(string,start,len)

fn:substring(string,start) Returns the substring from the start position to the specified length. Index of the first character is 1. If length is omitted it returns the substring from the start position to the end

Example: substring('Beatles',1,4)

Result: 'Beat'

Example: substring('Beatles',2)

Result: 'eatles'

fn:string-length(string)

fn:string-length() Returns the length of the specified string. If there is no string argument it returns the length of the string value of the current node

Example: string-length('Beatles')

Result: 7

More functions : http://w3schools.com/xpath/xpath_functions.asp

Former Member
0 Kudos

Hi Moorthy,

Thanks 4 the reply. Can u explain me how to solve this using Message Mapping ? I mean which Node functions to use to get the desired output.

Thanks in advance,

Jose Augastine