Using max function with dates in xquery
Oxygen general issues.
-
- Posts: 4
- Joined: Sat Nov 12, 2005 1:06 am
Using max function with dates in xquery
I am trying to find the maximum date in an xml file using xquery. I believe I shold be able to do so using the following.
however this error message occurs:
SystemID: null
Description: E Failure converting {1975-02-20} to a number
This code
produces the same message. Deleting the line
gets rid of the error. I cannot use variable in any way without causing the error. Can anyone explain what is wrong?
Regards,
Daron.
Code: Select all
declare namespace q2 = "http://daron.ryan.org/namespace/q2.html";
<younger_workers>
{
let $workers:= doc("q2.xml")//q2:workers
let $youngest :=xs:date(max($workers//q2:bdate))
return $youngest
}
</younger_workers>
SystemID: null
Description: E Failure converting {1975-02-20} to a number
This code
Code: Select all
declare namespace q2 = "http://daron.ryan.org/namespace/q2.html";
<younger_workers>
{
let $workers:= doc("q2.xml")//q2:workers
let $youngest :=xs:date(max($workers//q2:bdate))
let $copy := $youngest
return <blank></blank>
}
</younger_workers>
Code: Select all
let $copy := $youngest
gets rid of the error. I cannot use
Code: Select all
$youngest
Regards,
Daron.
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Post by alex_jitianu »
Hello,
All items in the argument of the max() function must be numeric or derived from a single base type.
So the items from "$workers//q2:bdate" are being converted to numeric type but something like {1975-02-20} cannot be converted to a number.
You can try the following code :
Hope it helps,
Alex
All items in the argument of the max() function must be numeric or derived from a single base type.
So the items from "$workers//q2:bdate" are being converted to numeric type but something like {1975-02-20} cannot be converted to a number.
You can try the following code :
Code: Select all
declare namespace q2 = "http://daron.ryan.org/namespace/q2.html";
<younger_workers>
{
let $workers:= doc("q2.xml")//q2:workers
let $dates :=$workers//q2:bdate
let $youngest :=max(for $date in $dates return xs:date($date))
return $youngest
}
</younger_workers>
Alex
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service