Hi Rafan,

I managed to find a simpler solution... so logging it here for anyone like me 
who might be desperately looking for it.

This is not standard BPEL and depends on Saxon's Extension mechanism to call 
Java classes, but works just fine in my case.

In the example below I am using Java's SimpleDateFormat to format the date and 
copying it into an xsd:string called result. 
Since SimpleDateFormat needs to be instantiated with the pattern, there is the 
first call with sdf:new(pattern)


<bpel:copy xmlns:sdf="java:java.text.SimpleDateFormat">
                <bpel:from 
expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">            
                    
                    sdf:format(sdf:new('yyyyMMDDHHmmss'), current-dateTime())
                </bpel:from>

                <bpel:to part="payload" variable="output">
                    <bpel:query 
queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[tns:result]]></bpel:query>
                </bpel:to>
            </bpel:copy>


More details about Saxon's extension mechanism here.
http://saxon.sourceforge.net/saxon7.9.1/extensibility.html

regards,
Josef



-----Original Message-----
From: Rafal Rusin [mailto:[email protected]] 
Sent: 11 August 2010 17:20
To: [email protected]
Subject: Re: Date manipulation functions in BPEL

On Wed, Aug 11, 2010 at 4:55 PM, Josef Bajada <[email protected]> wrote:
> Thanks Rafan.
>
> It seems such an overkill to need to have a separate XSL style-sheet just to 
> format a date variable to a string.
> Maybe there is a simpler way?

Currently it's not possible.
You can create jira issue for it.

>
> Regards,
> Josef
>
>
>
> -----Original Message-----
> From: Rafal Rusin [mailto:[email protected]]
> Sent: 11 August 2010 15:05
> To: [email protected]
> Subject: Re: Date manipulation functions in BPEL
>
> Hello,
>
> On Wed, Aug 11, 2010 at 1:56 PM, Josef Bajada <[email protected]> wrote:
>> Hi Rafal,
>>
>> Thanks for your feedback. I had forgot to include the xmlns:xsd namespace. 
>> It worked like a charm now.
>>
>> Any idea about how to use XSLT functions? I would like to use the 
>> format-dateTime() but I can't find how to use it directly.
>>
>
> I think the best way is to use XSLT transforms, since those XSLT
> functions require XSLT context in Saxon.
> This should help:
> https://svn.apache.org/repos/asf/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/
>
>> Thanks,
>>
>> Josef
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: Rafal Rusin [mailto:[email protected]]
>> Sent: 11 August 2010 13:43
>> To: [email protected]
>> Subject: Re: Date manipulation functions in BPEL
>>
>> On Wed, Aug 11, 2010 at 12:58 PM, Josef Bajada <[email protected]> 
>> wrote:
>>> I am trying to use ODE for some simple BPEL proof-of-concepts and I have
>>> stumbled upon some difficulties to manipulate dates and times.
>>>
>>> I have managed to call current-dateTime() through XPath 2.0 as follows:
>>>
>>>
>>>
>>>                <bpel:from part="payload" variable="output">
>>>
>>>                    <bpel:query
>>> queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"><![CDATA[
>>> current-dateTime()]]></bpel:query>
>>>
>>>                </bpel:from>
>>>
>>>
>>>
>>> However, I haven't managed to perform a simple addition like this:
>>>
>>>
>>>
>>>                <bpel:from part="payload" variable="output">
>>>
>>>                    <bpel:query
>>> queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"><![CDATA[
>>> current-dateTime() + xs:dayTimeDuration('P1D')]]></bpel:query>
>>>
>>>                </bpel:from>
>>
>> Such thing worked for me:
>>
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>>            <bpws:copy>
>>                <bpws:from
>> expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"><![CDATA[current-dateTime()
>> + xsd:dayTimeDuration('P1D')]]></bpws:from>
>>                <bpws:to><![CDATA[$response.body/hello:text]]></bpws:to>
>>            </bpws:copy>
>>
>> Please try to make it pass first.
>>
>>>
>>>
>>>
>>>
>>> I also don't have any idea how to call an XSLT function such as
>>> format-dateTime().
>>>
>>>
>>>
>>> I wish to do something like the following, but I have no idea how to do
>>> it in BPEL. When I try the following I get an error saying that I cannot
>>> use format-dateTime() in a non-XSLT context:
>>>
>>>
>>>
>>> format-dateTime(current-dateTime(), "Y-M-D H:m:s"))
>>>
>>>
>>>
>>> thanks,
>>>
>>> Josef
>>>
>>>
>>
>>
>>
>> --
>> Regards,
>> Rafał Rusin
>> http://rrusin.blogspot.com
>>
>
>
>
> --
> Regards,
> Rafał Rusin
> http://rrusin.blogspot.com
>

-- 
Regards,
Rafał Rusin
http://rrusin.blogspot.com

Reply via email to