我无法找到以下解释.我已经制作了这个测试脚本以解决我之前的问题.
xquery version "3.0" ;
declare default function namespace 'local' ;
declare function local:is-img-only( $element as element() ) as xs:boolean {
($element/child::*[1] instance of element(img))
and (fn:not($element/child::*[2]))
and (fn:normalize-space($element) = '')
} ;
let $in-xml := <myxml>
<p id="1">
<img id="1"/>
</p>
<p id="2">
<img id="1"/>
hello
</p>
<p id="3">
<img id="1"/>
</p>
<p id="4">
<blockquote>hello</blockquote>
<img id="1"/>
</p>
<p id="5">
<img id="1"/>
<img id="2"/>
</p>
</myxml>
Run Code Online (Sandbox Code Playgroud)
然后,使用以下内容if then else:
for $p in $in-xml/p
return if …Run Code Online (Sandbox Code Playgroud)