From: Harris, B. T. (GSFC-5870) <ber...@na...> - 2023-03-14 12:50:55
|
No matter what I do, I cannot get a useful (more than "$result") %:assertXPath to work in this case xquery version "3.1"; import module namespace inspect="http://exist-db.org/xquery/inspection"; import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql"; declare namespace xhtml = "http://www.w3.org/1999/xhtml"; declare %test:arg("error", "Bad Request") %test:arg("description", "Invalid ResourceID") %test:arg("extraHtml") %test:assertXPath("$result//*:html") (: %test:assertXPath("$result//*:html/*:head[*:title = 'Bad Request']") %test:assertXPath("$result/xhtml:html/xhtml:body/xhtml:p[@class = 'ErrorMessage']") :) function local:errorHtml( $error as xs:string, $description as xs:string, $extraHtml as node()?) as node() { let $result := <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>{$error}</title> </head> <body> <p class='ErrorMessage'><b>Message: </b>{$error}</p> <p class='ErrorDescription'><b>Description: </b>{$description}</p> {$extraHtml} </body> </html> return $result }; let $f := local:errorHtml#3 return test:suite($f) It always results in <testsuites> <testsuite package="http://www.w3.org/2005/xquery-local-functions" timestamp="2023-03-14T08:28:16.065-04:00" tests="1" failures="1" errors="0" pending="0" time="PT0.002S"> <testcase name="errorHtml" class="local:errorHtml"> <failure message="assertXPath failed." type="failure-error-code-1">$result//*:html</failure> <output> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Bad Request</title> </head> <body> <p class="ErrorMessage"> <b>Message: </b>Bad Request</p> <p class="ErrorDescription"> <b>Description: </b>Invalid ResourceID</p> </body> </html> </output> </testcase> </testsuite> </testsuites> Or <testcase name="errorHtml" class="spasexq:errorHtml"> <error type="err:XPST0081" message="It is a static error if a QName used in an expression contains a namespace prefix that cannot be expanded into a namespace URI by using the statically known namespaces. Error while evaluating expression: $result//xhtml:html. No namespace defined for prefix xhtml:html"/> </testcase> If I use the xhtml namespace in the assertXPath annotation. I found someone report a similar problem on stackoverflow in 2016 but it is not clear to me how it was resolved. This is on exist-db 6.2.0 and Java 11. Does anyone know what I am doing wrong? Thanks. Bernie Harris |