0

I am trying to run some Xquery code in a java program and I am using the Saxon free java library for this purpose.

Now for some reason I am getting repeated "duplicate function definition" errors when I run this code-- this error is occurring for the "Functx" Xquery library which I downloaded from xqueryfunctions.com.

I dont understand what is wrong here? I am making straightforward calls to some functions in the FunctX Library.

Given below is a section of the error log- it also mentions the line numbers for the "duplicate functions"-- however, when I went to the 2 line numbers I saw that one line number corresponded to the start of that function, while the other line number closed that function.

The library that I am using is at this URL--
http://e0aad1ab954aa14b69e0-bd55729d8fadb0b3214bfee0a8fb65e0.r16.cf1.rackcdn.com/functx-1.0.xq

A section of the error log is given below--

Error on line 2488 column 4 of functx-1.0.xq:
  XQST0034 XQuery static error near #...ion the duration :) declare#:
    Duplicate definition of function functx:total-days-from-duration (see line 2
 484 in
  http://e0aad1ab954aa14b69e0-bd55729d8fadb0b3214bfee0a8fb65e0.r16.cf1.rackcdn.c
 om/functx-1.0.xq)
Error on line 2502 column 4 of functx-1.0.xq:
  XQST0034 XQuery static error near #...ion the duration :) declare#:
    Duplicate definition of function functx:total-hours-from-duration (see line
 2498 in
 http://e0aad1ab954aa14b69e0-bd55729d8fadb0b3214bfee0a8fb65e0.r16.cf1.rackcdn.c
 om/functx-1.0.xq)
 Error on line 2516 column 4 of functx-1.0.xq:
 XQST0034 XQuery static error near #...ion the duration :) declare#:
   Duplicate definition of function functx:total-minutes-from-duration (see lin
 e 2512 in
 http://e0aad1ab954aa14b69e0-bd55729d8fadb0b3214bfee0a8fb65e0.r16.cf1.rackcdn.c
 om/functx-1.0.xq)
Error on line 2530 column 4 of functx-1.0.xq:
  XQST0034 XQuery static error near #...ion the duration :) declare#:
    Duplicate definition of function functx:total-months-from-duration (see line
2526 in
  http://e0aad1ab954aa14b69e0-bd55729d8fadb0b3214bfee0a8fb65e0.r16.cf1.rackcdn.c
 om/functx-1.0.xq)
Error on line 2544 column 4 of functx-1.0.xq:
  XQST0034 XQuery static error near #...ion the duration :) declare#:
    Duplicate definition of function functx:total-seconds-from-duration (see lin
 e 2540 in
  http://e0aad1ab954aa14b69e0-bd55729d8fadb0b3214bfee0a8fb65e0.r16.cf1.rackcdn.c
 om/functx-1.0.xq)
Error on line 2558 column 4 of functx-1.0.xq:
  XQST0034 XQuery static error near #...e string to trim :) declare#:
    Duplicate definition of function functx:total-years-from-duration (see line
  2554 in
 http://e0aad1ab954aa14b69e0-bd55729d8fadb0b3214bfee0a8fb65e0.r16.cf1.rackcdn.c
 om/functx-1.0.xq)

Now, looking at the last error as shown above-- the line numbers for the duplicate function definition error in functx-1.0.xq are "2558" and "2554"

The relevant code from the file functx-1.0.xq for lines 2554-2558 is now given below--

 declare function functx:total-years-from-duration 
   ( $duration as xs:yearMonthDuration? )  as xs:decimal? {

    $duration div xs:yearMonthDuration('P1Y')
  } ;

How do I resolve this error?

Arvind
  • 6,404
  • 20
  • 94
  • 143
  • 1
    Did you try to track down some [short example code](http://pscode.org/sscce.html) so we can reproduce the error? – Jens Erat Nov 22 '12 at 17:00
  • @Ranon- do you mean the java code that I was running? Its a custom crawler and I cannot share the code -- however the section that is causing the error is invoking "functx:pad-integer-to-length" -- that is the only function from the functx library that this code is invoking-- also i ran the java code just before I added the functx function call, and it was running fine then....basically the function I have invoked adds some zeros to the beginning of a numeric value to increase the character-length of that numeric value... – Arvind Nov 22 '12 at 17:07
  • 1
    Your mistake must be somewhere during importing the functx module. The module itself works fine, I just checked. If you e.g. import this module twice, such errors could occur. Or maybe you have a function of your own with the same name in this namespace. This is impossible to say, as it depends on your Java code. The call of the function is not important, as this is a static error and something goes wrong before. If you can not share the code it is impossible ro really help you. – dirkk Nov 22 '12 at 17:17
  • 1
    I'm not looking for all your crawler code, don't even want to read it. Did you try reducing your code to a minimal problem containing least possible java code? Throw everything out which is irrelevant and share that code. Without some code, how should anybody be able to help you? – Jens Erat Nov 22 '12 at 17:35
  • @dirkk -- I did see one thing-- there is another xquery file that I am importing- and this file also imports the functx module (for its own use)-- how do I use the functx module directly in my code, as well as import it within the second module which is also imported into my code? Thanks.... – Arvind Nov 22 '12 at 19:33
  • @Ranon pls refer my comment above this one... – Arvind Nov 22 '12 at 19:33
  • possible duplicate of [Duplicate error when adding XAttribute to XElement](http://stackoverflow.com/questions/12954846/duplicate-error-when-adding-xattribute-to-xelement) – Paul Sweatte Jun 25 '14 at 05:37

1 Answers1

0

When you use xquery engine in a loop for example (my case) and you use one single object to execute multiple xquery that import the same function the engine will try to import the function each time, so you have duplicate the second loop.

To solve that I simply reset the object configuration each time I execute the xquery (in my Java problem I created a class that run the xquery engine and do al lthe configuration from 0 each time, so that previous run does not mess up the new run).

B001ᛦ
  • 2,036
  • 6
  • 23
  • 31
CodeKiller
  • 67
  • 1
  • 7