Friday, December 26, 2008

Magikkk of 'Translate'

Ahhh...Writing blog after a longtime. During this time, got an oppurtunity to diagonise now thinking of sharing some of my knowledge and experiences with all.

Here I am going to discuss a very small function of XSLT:- TRANSLATE.
Translate function returns inputString with occurrences of characters in fromString replaced by the character at the corresponding position in toString. This function takes 3 parameters.

SYNTAX: translate(inputString as string,fromString as string,toString as string)

If we deal in currency values, often we see that the value is separated by commas. For example, Value1=2,000,000/Value2=3,000/Value3=30,000

Now suppose you need to store this value in the database. To acheive this you need to remove all the commas from the incoming value. For this purpose we have to use the TRANSLATE function.

For the above scenario, use Translate as:
translate(inputString as string,fromString as string,toString as string)

inputString as string= Your input XPath, for instance, /ns0:Order/ns0:Lines/ns0:UnitPrice/ns0:Money
fromString as string=","
toString as string=""

Now use a conversion function 'Number' to convert the string in number. Thats it and you are done.
Hope I have cleared my point.

Keep learning with me and MERRY CHRISTMAS to all the readers.

No comments: