I have a testing function which takes a document as its argument and transforms it from XML into HTML. For it, I would like to use some tests. %test:assertXPath seems to be a good candidate in this case. However, I can’t understand its behavior if I use the whole path.
My function:
xquery version "3.0";
module namespace cust = 'http://46.28.111.241:8081/exist/db/apps/myapp/modules/cust';
declare namespace tei = 'http://www.tei-c.org/ns/1.0';
declare namespace test = 'http://exist-db.org/xquery/xqsuite';
declare
%test:args('<TEI xmlns="http://www.tei-c.org/ns/1.0">
<text>
<body>
<div n="1">
<head>Heading</head>
<p>paragraph</p>
</div>
</body>
</text>
</TEI>',
'/db/apps/myapp/resources/xslt/style-web.xsl')
%test:assertXPath('$result//@*')
%test:assertXPath('$result//*')
%test:assertXPath('$result//*[@class = "chapter"]')
%test:assertXPath('$result/html')
function cust:transform($doc as element(), $styleSheet as xs:anyURI) as node() {
let $styleSheet := doc($styleSheet)
let $document :=
(
<book n='1'>{($doc//tei:div[@n='1'])[1]}</book>
)
let $finale := transform:transform($document, $styleSheet, ())
return $finale
};
It is apparent the only one assertion which does not pass is the $result/html. Why?
解决方案
Your missing the namespace from your XPath assertion. The <html> element you are producing is in the http://www.w3.org/1999/xhtml namespace.
So you need to change your assertion to either:
%test:assertXPath('$result/*:html')
or you need to declare the namespace prefix in your prolog using declare namespace xhtml = "http://www.w3.org/1999/xhtml"; and then your assertion would look like: