[xquery-talk] suppressing emission of elements if no value

Michael Kay mhk at mhk.me.uk
Thu Jun 10 20:09:07 PDT 2004


If a/b is complex then it calls for a variable:

let $c := a/b return 
  if ($c) then <x>{$c}</x> else ()

You could also do

<x>{a/b}</x>[*]

but most implementations would probably construct the empty <x> and then
discard it, which is inefficient.

Michael Kay 

> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of Francis Upton
> Sent: 10 June 2004 17:33
> To: talk at xquery.com
> Subject: [xquery-talk] suppressing emission of elements if no value
> 
> I have an application where I am generating XQuery and have a 
> requirement 
> that if there is no value for an expression, it should not 
> generate an element.
> 
> So I would like something like:
> 
>    element x { a/b }
> 
> to emit nothing, assuming a/b is empty.
> 
> This expression emits <x></x> when a/b is empty.
> 
> The only way I can think of to do this is to wrap a condition 
> around it like:
> 
>    if (a/b) then element x { a/b } else ()
> 
> Is there any other way to approach this?  I don't like wrapping an if 
> statement around it because the "a/b" can be quite complex and time 
> consuming to compute and there could be quite a number of 
> these in the 
> types of documents I'm working with.  I realize this may be 
> something that 
> some XQuery engines might optimize; if that's the case it's 
> probably fine.
> 
> Thanks for your help.
> 
> Francis
> 
> 
> Francis Upton IV
> H/W 510 835 3123
> C 510 432 1589
> F 501 648 1464 (yes, it is 501)
> blog: http://www.nogoop.com/mt/ 
> 
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
> 




More information about the talk mailing list