Wednesday, July 16, 2008

Playing with XSLT- Part 2

Hmmm..Again I am back with some more XSLT stuff.

Importing some data from a .csv file(containing date as one field) and inserting it into the database.
If the date field (from csv file) is passed in the format 'YYYY-MM-DD', it works fine. But the problem comes when you try to pass the date value in format 'DD-MM-YYYY' or in any other formats.

To explain the above case I have taken the format 'DD-MM-YYYY' as subject.
Weel to acheive it you need to do is to create some embedded java code or use the following in the assign or transformation activity:(subsitute the tns:date with your variable)

concat(substring(tns:Date,orcl:last-index-within-string(tns:Date,"-") + 2.0,4.0),"-",substring(tns:Date,orcl:index-within-string(tns:Date,"-")+2,2.0),"-",substring-before(tns:Date,"-"))


1 comment:

Johan Rydström said...

A much easier way is to get it right when reading the file. Add the attribute nxsd:dateFormat="yyyyMMdd" (or whatever your date format is) and the file adapter will do the transformation from string to xsd:date for you!