Can you explain this more:

($fn($el)[$bool], $el)[1]


Construct a sequence of
( Call the function $fn  given the argument $el
   if $bool is true the the result of the function is used otherwise () ,
   The element $el )

This produces a 1 or 2 element sequence.

[1] takes the first element which is either the wrapped $el or just $el


I would put this example in the camp of "advanced xquery"




From: Misztur, Chris [mailto:[email protected]]
Sent: Monday, December 16, 2013 12:33 PM
To: James Fuller; David Lee
Cc: David Carlisle; [email protected]
Subject: RE: [xquery-talk] Wrapping element conditionally

Can you explain this more:

($fn($el)[$bool], $el)[1]

[Description: Description: 
C:\Users\bduffy\AppData\Local\Microsoft\Windows\Temporary Internet 
Files\Content.Outlook\WXCD6RUK\MF_4C_email (2).jpeg]

Chris Misztur | Engineer, Business Systems
1000 Allanson Rd, Mundelein, IL 60060 (Map<http://g.co/maps/kxf8e>)
Office +1 847 837-3729 | Cell +1 312 504-0681
www.macleanfoggcs.com<http://www.macleanfoggcs.com/>

From: James Fuller [mailto:[email protected]]
Sent: Monday, December 16, 2013 11:10 AM
To: David Lee
Cc: David Carlisle; Misztur, Chris; [email protected]<mailto:[email protected]>
Subject: Re: [xquery-talk] Wrapping element conditionally

and for a bit of xquery 3.0 fun

xquery version "3.0";

let $apply:= function($bool,$fn,$el){ ($fn($el)[$bool], $el)[1] }

let $wrap := true() ,
    $p := <p>something here</p>
return
$apply(
   $wrap,
   function($el){<html><body>{$el}</body></html>},
   $p)



On Mon, Dec 16, 2013 at 6:01 PM, David Lee 
<[email protected]<mailto:[email protected]>> wrote:
FYI the key to understanding XQuery (and XSLT) is that you are not "printing 
lines" your generating element.  *full elements* with these constructs.
You cant just   printf("<html>")  then later printf("</html>")

You are constructing an entire element including the start, end and body all at 
once.
So you cant conditionally include or exclude half the markup.


-----Original Message-----
From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]<mailto:[email protected]>] On Behalf Of 
David Carlisle
Sent: Monday, December 16, 2013 11:47 AM
To: Misztur, Chris; [email protected]<mailto:[email protected]>
Subject: Re: [xquery-talk] Wrapping element conditionally

On 16/12/2013 16:28, Misztur, Chris wrote:
> How would I get the output to look like:
>
> <html><body><p/></body><html>
>
> Or just:
>
> <p/>

<html><body><p>something here</p></body></html>/
    (if($wrap) then . else body/p)

David


________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England and Wales 
with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is powered by 
MessageLabs.
________________________________________________________________________
_______________________________________________
[email protected]<mailto:[email protected]>
http://x-query.com/mailman/listinfo/talk
_______________________________________________
[email protected]<mailto:[email protected]>
http://x-query.com/mailman/listinfo/talk


________________________________

The contents of this message may be privileged and confidential. Therefore, if 
this message has been received in error, please delete it without reading it. 
Your receipt of this message is not intended to waive any applicable privilege. 
Please do not disseminate this message without the permission of the author.

Please consider the environment before printing this e-mail

<<inline: image001.jpg>>

_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to