【发布时间】:2018-01-10 15:12:06
【问题描述】:
我在多次测试后提出这个问题,以验证我的表达是否正确。它是,虽然它仍然没有通过。
我正在使用经典的 dispatch/passthru 函数将 XML 数据库(具有使用命名空间 spip 的自己的架构)转换为 XML 文件(使用另一个架构)。
declare function p($node as element(spip:p)+, $options as map(*)) {
switch ($node)
case ( $node/spip:* instance of element(spip:img) and fn:not($node/text()[fn:normalize-space(.) != '']) ) return passthru($node, $options)
case ( $node/spip:* instance of element(spip:figure) and fn:not($node/text()[fn:normalize-space(.) != '']) ) return passthru($node, $options)
case ( $node/spip:* instance of element(spip:blockquote) and fn:not($node/text()[fn:normalize-space(.) != '']) ) return passthru($node, $options)
default return
<para>
<alinea>{ passthru($node, $options) }</alinea>
</para>
};
case 表达式主要测试<p> 元素中子元素($node/spip:*) 的性质以及该<p> 元素是否包含一些文本。有用!至少对于 <blockquote> 和 <figure> 的孩子来说,但它不适用于元素 <img>。
具有<p><img/></p> 结构的节点正在通过默认情况,而像 <p><blockquote>xxx</blockquote></p> 或 <p><figure>xxx</figure></p> 这样的节点正在通过测试。
我尝试更具体地测试<img> 元素:
case ($node/child::*[1] instance of element(spip:img))
奇怪的是,两个测试都在 if then else 表达式中正常工作。然后我就有了我想要的结果..
关于改进测试和妥善处理<p><img/></p> 的任何建议?
【问题讨论】:
标签: xml switch-statement xquery