XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
(Deleted User) Subject: Subtract times
Author: (Deleted User)
Date: 14 Nov 2008 09:55 AM
Hi you all,

I want to subtract two time fields. Googling learned me that the op:subtract function would work and that if you add this namespace prefix you can just deduct to variables. I think I am close to a solution with the code below, however it keeps telling me:

Static type error. Types 'element(DateEnd, xs:anyType)' and 'element(DateStart, xs:anyType)' are invalid argument types for binary operator '-'.

though I have associated a schema (right mouse button on doc node in source doc of xquery) in which these two fields are defined as xsd:date fields. Can you assist?

declare variable $arg1 as element(DateStart) external;
declare variable $arg2 as element(DateEnd) external;

<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:op="http://www.w3.org/2001/12/xquery-operators">
<Requests>
<Request>
<DateStart>
{$arg2 - $arg1}
</DateStart>
</Request>
</Requests>
</eExact>

Regards,


Cynthia

Postnext
Minollo I.Subject: Subtract times
Author: Minollo I.
Date: 14 Nov 2008 10:08 AM
What XQuery processor is reporting the error you mentiond running that XQuery?

Postnext
(Deleted User) Subject: Subtract times
Author: (Deleted User)
Date: 14 Nov 2008 03:45 PM
Hi Minollo,

Processor is DataDirect Xquery. I am also trying this version to bind a variable to an xml element, but there are some mistakes there as well:



<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd" xmlns:op="http://www.w3.org/2001/12/xquery-operators">
<Requests>
<Request>
for $arg1 in doc('file:///e:/Synergy_ASP/HR/Verlofaanvragen/Workflow_Verlof_basis.xml')/root/row/DateStart
return
<DateStart>
doc('file:///e:/Synergy_ASP/HR/Verlofaanvragen/Workflow_Verlof_basis.xml')/root/row/DateStart
</DateStart>
for $arg2 in doc('file:///e:/Synergy_ASP/HR/Verlofaanvragen/Workflow_Verlof_basis.xml')/root/row/DateEnd
return
<DateEnd>
doc('file:///e:/Synergy_ASP/HR/Verlofaanvragen/Workflow_Verlof_basis.xml')/root/row/DateEnd
</DateEnd>
<Diff>
{$arg2 - $arg1}
</Diff>
</Request>
</Requests>
</eExact>

Postnext
(Deleted User) Subject: Subtract times
Author: (Deleted User)
Date: 14 Nov 2008 05:42 PM
Hi again,

I succeeded in declaring my variables, but the actucal subtraction doesn't work yet, what am I missing?

for $row in doc('file:///e:/Synergy_ASP/HR/Verlofaanvragen/Workflow_Verlof_basis.xml')/root/row
let $arg1 := xs:time($row/DateStart),
$arg2 := xs:time($row/DateEnd)
return
<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd" xmlns:op="http://www.w3.org/2001/12/xquery-operators">
<Requests>
<Request>
<DateStart>
{$arg2-$arg1}
</DateStart>
<DateEnd/>
<Diff>
</Diff>
</Request>
</Requests>
</eExact>

Thanks!


Cynthia

Postnext
Minollo I.Subject: Subtract times
Author: Minollo I.
Date: 14 Nov 2008 08:03 PM
What is the error you are getting? Maybe the format in the elements you are interpreting as xs:time is not correct? The following examples may help:

xs:time('23:23:23') - xs:time('23:22:23')
result: PT1M

xs:date("2008-11-15")-xs:date("2008-11-14")
result: P1D

xs:dateTime("2008-11-15T23:12:23")-xs:dateTime("2008-11-14T23:11:23")
result: P1DT1M

The returned values are xs:duration types; you can use various functions to handle xs:duration, like hours-from-duration(), days-from-duration(), ...; a word of caution; those functions are specified to be less smart than you might think: hours-from-duration("P1D") is 0 (not 24 as I expected); days-from-duration("P1D") is 1.

Posttop
(Deleted User) Subject: Subtract times
Author: (Deleted User)
Date: 15 Nov 2008 03:56 AM
Morning!

Ok, waking up and of course right away curious if there is a post. Now got the answer, cause I realized my types were xs:time but if was just giving back <DateStart>11:00:00-10:00:00</DateStart>. Moved the subtraction to the top of my xquery file, assigned the subtraction outcome to $arg3 and placed {$arg3} in my xml tag. Et voila!

Thank you so much!

Cynthia

for $row in doc('file:///e:/Synergy_ASP/HR/Verlofaanvragen/Workflow_Verlof_basis.xml')/root/row
let $arg1 := xs:time($row/DateStart),
$arg2 := xs:time($row/DateEnd),$arg3:= ($arg2)-($arg1)

return

<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd" xmlns:op="http://www.w3.org/2001/12/xquery-operators">
<Requests>
<Request>
<DateStart>
</DateStart>
<DateEnd/>
<Diff>
{$arg3}
</Diff>
</Request>
</Requests>
</eExact>

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.