I raise this question after multiples tests in order to verify that my expression is correct. And it is, although it still doesn't go through.
I'm using the classic dispatch/passthru function to convert an XML database (with its own schema using the namespace spip
) to XML files (with another schema).
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>
};
The case expressions basically test the nature of the child element ($node/spip:*
) in a <p>
element and whether this <p>
element contains some text. It works! At least for the childs <blockquote>
and <figure>
, but it doesn't for the element <img>
.
Nodes with that structure <p><img/></p>
are going through the default case, whereas nodes like <p><blockquote>xxx</blockquote></p>
or <p><figure>xxx</figure></p>
are passing the test.
I have tried to be more specific in testing the <img>
element with :
case ($node/child::*[1] instance of element(spip:img))
The weird thing is that both tests are working fine in a if then else
Expression. Then I have the result I want..
Any suggestion.s for improving the tests and having <p><img/></p>
properly treated ?
switch
and not thetypeswitch
. But you are right, I get a proper result withif then else
. However, I have more "case" than those in my example, therefore the code will look a bit messy. Still wondering why my test/expression is not evaluated the same way inif
and incase
. Thanks for your help. – Alexandriaalexandrian