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

Mike Carey mcarey at bea.com
Fri Jun 11 17:42:42 PDT 2004


NOTE: I've seen this come up repeatedly as something real XQuery
customers / users want to do.  It's too bad there isn't a built-in
simpler way to do this in XQuery itself!

Mike Carey

-----Original Message-----
From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On Behalf
Of Michael Kay
Sent: Thursday, June 10, 2004 11:09 AM
To: 'Francis Upton'; talk at xquery.com
Subject: RE: [xquery-talk] suppressing emission of elements if no value

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
> 


_______________________________________________
talk at xquery.com
http://xquery.com/mailman/listinfo/talk



More information about the talk mailing list