Project

Profile

Help

XQuery syntax error

Added by Anonymous almost 15 years ago

Legacy ID: #7165417 Legacy Poster: Gilbert Polo (gpolo1)

In the process of evaluating Saxon-SA 9.1.0.6J. Existing queries are currently executing with Saxon-B 8.7.1J with no problem. Specifically it complains about the random key word. Provided a code snippet below. Any help would be greatly appreciated. order by number($SEQUENCE) random return <BLAHBLAH = "{xs:integer($SEQUENCE)}" />


Replies (6)

Please register to reply

RE: XQuery syntax error - Added by Anonymous almost 15 years ago

Legacy ID: #7165430 Legacy Poster: Gilbert Polo (gpolo1)

The exact error is XPST0003: XQuery syntax error in #...NCE) random return#: expected "return", found name "random"

RE: XQuery syntax error - Added by Anonymous almost 15 years ago

Legacy ID: #7165627 Legacy Poster: Michael Kay (mhkay)

Well, it looks like a syntax error to me, so I would expect it to complain. Perhaps you meant order by number($SEQUENCE), random return <BLAH/> If not, what did you mean, and what makes you think your query is correct?

RE: XQuery syntax error - Added by Anonymous almost 15 years ago

Legacy ID: #7172399 Legacy Poster: Gilbert Polo (gpolo1)

Unfortunately, I was not the designer of this XQuery, but I suspect the original author wants to order the resultset by a specific attribute but then wants to return the resultset in a random order. This is due to the fact that the xml file is usually ordered anyhow. Does this make sense? I want it ordered, but random at the sametime. So, I guess what you're saying is that this is not proper XQuery syntax in the first place. However, it does work in version 8.7.1J

RE: XQuery syntax error - Added by Anonymous almost 15 years ago

Legacy ID: #7172621 Legacy Poster: Michael Kay (mhkay)

Correct, this is not valid XQuery syntax. And it's not just that Saxon 8.7.1 was released before XQuery was finalized, I don't think it has ever been correct XQuery syntax. Moreover, I don't think it has ever been permitted by Saxon: this query for $SEQUENCE in 1 to 10 order by number($SEQUENCE) random return <BLAHBLAH = "{xs:integer($SEQUENCE)}"/> in Saxon 8.7.1 gives exactly the error you are reporting: Saxon 8.7.1J from Saxonica Java version 1.6.0_13 Compiling query from e:\temp\test.xq Error on line 2 column 28 of file:/e:/temp/test.xq: XPST0003: XQuery syntax error in #...mber($SEQUENCE) random return#: expected "return", found name "random" Failed to compile query You didn't cite the full query, so of course this may not be an accurate simulation.

RE: XQuery syntax error - Added by Anonymous almost 15 years ago

Legacy ID: #7173099 Legacy Poster: Gilbert Polo (gpolo1)

Is there any way to order a resultset by an attribute and then use some sort of function to randomize/scramble the resultset. The problem is in the order of the XML elements within the existing XML file. I need the resultset in random order. Thanks.

RE: XQuery syntax error - Added by Anonymous almost 15 years ago

Legacy ID: #7173171 Legacy Poster: Michael Kay (mhkay)

There's no built in function to randomize, but you can use the EXSLT random:random-sequence() function. For example declare namespace random = "http://exslt.org/random"; let $rand := random:random-sequence(count($SEQ)) for $n at $pos in $SEQ order by $rand[$pos] ... I'm afraid I can't understand why you would want to sort the sequence before randomizing it.

    (1-6/6)

    Please register to reply