cancel
Showing results for 
Search instead for 
Did you mean: 

Split a string

Former Member
0 Kudos

Hi Experts,

The requirement is- we have a phone number (for e.g. 07 9277 1922). now we want only '07' from this. How we can do this using XSLT?

Many thanks in advance.

Edited by: Mohan Arya on Dec 1, 2009 5:02 AM

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

instead of using substring() method, I'd use a more flexible way : split(String regex) method that returns an array of String according to the regular expression provided as input param, like this :

String[] token = "XX xx xxxx xxx xxx".split(" ");

return token[0];

of course, you must test array is not empty, maybe catch exceptions, etc ...

Rgds

Chris

PS: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)

Former Member
0 Kudos

Hi Arya,

Check this link

http://www.w3schools.com/Xpath/xpath_functions.asp

Above link in Functions on strings available, check SubString function

Ex:

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

Result: 'Beat'

Example: substring('Beatles',2)

Result: 'eatles'

Regards

Ramesh

Former Member
0 Kudos

<xsl:template match="/aaa">

<xxx>

<xsl:value-of select="substring(.,1,3)"/>

</xxx>

</xsl:template>

in this if you give <aaa>SAP PI XSLT</aaa>

then output will be <xxx>SAP</xxx>

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Mohan,

There are predefined methods available to split the string(SubString function)

or

use JAVA code in XSLT Mapping,its very easy,use subString function,it will work it out.

or

use UDF ,use substring function in JAVA ,you can achieve easily.

Regards,

Raj