• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Using variables in tXSLT "output file" field

#1 2012-06-15 11:45:17

saukema
Member
Company: XSed
Registered: 2011-09-14
Posts: 126
Website

Using variables in tXSLT "output file" field

I created a simple job with some xslt looking like:

tXSLT --> tJavaFlex


In the tXSLT is put this:
context.JDE_tmpData+"Execute"+java.util.UUID.randomUUID().toString()+".xml"


In the tJavaFlex I put this:
xmlFilename = ((String)globalMap.get("tXSLT_1_OUTPUT_FILEPATH"));
xmlFilename +="/";
xmlFilename += ((String)globalMap.get("tXSLT_1_OUTPUT_FILENAME"));

When executing the job I get an error from the tJavaFlex that the file (Execute12b6fe77-e4de-46bc-b96e-fd2720d1c61c.xml) does not exist.

When I check the file that is created by the tXSLT, I can see a totally different filename.


I tried to do the same with a timestamp. This works most of the time, but sometimes I get the error. In those situations I can see:
File created: 20123015113050.xml
File error: 20123015113051.xml

So it looks like ((String)globalMap.get("tXSLT_1_OUTPUT_FILENAME")) is not actually getting the filename, but is recreating the filename with errors as result.


For now I created a work around by setting the filename to a global var (tSetGlobalVar), but I think it's actually a bug.

Offline

#2 2012-06-15 11:57:18

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: Using variables in tXSLT "output file" field

Hi

Yes. I check the Java code according to your description.

Code:

globalMap.put("tXSLT_1_OUTPUT_FILENAME",
                            (java.util.UUID.randomUUID().toString() + ".xml")

And

Code:

ttXSLT_1.transform(xmlSourcetXSLT_1,
                        new javax.xml.transform.stream.StreamResult(
                                new java.io.File(java.util.UUID.randomUUID()
                                        .toString()
                                        + ".xml")))

This is caused by java.util.UUID.randomUUID() method here. This method runs twice.
A workaround is to save context.JDE_tmpData+"Execute"+java.util.UUID.randomUUID().toString()+".xml" into another context variable(e.g. context.outfilename) in a tJava in the beginning of this job.

Regards,
Pedro


Only Paranoid Survive.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Using variables in tXSLT "output file" field

Board footer

Powered by FluxBB