XQuery doesn't execute

Issues related to W3C XQuery.
Posts: 2
Joined: Tue Aug 02, 2022 3:33 pm

XQuery doesn't execute

Post by DeepMohinman »

I have an XQuery problem:

Code: Select all

let $x := $document//AOSCAT_MetricDetail//table[@class="pretty-table"]
let $sum_of_statements_per_method := sum(
          for $a at $i in $x where $a != 0.0 return $a 
let $count_of_statements_per_method := count(
          for $a at $i in $x where $a != 0.0 return $a 
if ($count_of_statements_per_method != 0) then
    return <average_statements_per_method>{ 
    return <average_statements_per_method> 
       No data available 
Executing this XQuery with Saxon9 yields the following Error:
Error on line 103 column 39 of transform_2.xq:
XPST0003: XQuery syntax error in #...verage_statements_per_method>{#:
expected "else", found ">"
Static error(s) in query
But i dont understand why. In the same File a have a very similar XQuery expression and there's no problem at all...

Is anyone able to point me to where my mistake is ?

EDIT: But why does this work ok, then? :

Code: Select all

let $content_check := $document//AOSCAT_MainReport//div[@class="reportpart"][4]/h2/text()
if($content_check="Abstraction analysis") then                                                              
let $abstraction := $document//AOSCAT_MainReport//div[@class="reportpart"][4]/table//tr[2]//td[5]
    return <abstraction_level>{ fn:number(fn:normalize-space($abstraction))*100 }</abstraction_level>
    let $abstraction := 0
    return <abstraction_level>{ $abstraction }</abstraction_level>  
Martin Honnen
Posts: 93
Joined: Tue Aug 19, 2014 12:04 pm

Re: XQuery doesn't execute

Post by Martin Honnen »

The syntax of an `if` expression in XQuery is simply e.g. `if (condition-expression) then expression1 else expression2`, there is no `return` involved, neither in the `then expression1` nor in the `else expression2`.
Post Reply