[xquery-talk] What does [.] do.

David Lee dlee at calldei.com
Mon Jan 27 07:34:48 PST 2014


> I don't have a preferred order of precedence and no they shouldn't both be there.
The key word is "shouldnt" ... minor code variants can turn that into "even if it ever happens the code wont break"
Sometimes thats worth doing ... sometimes you WANT the code to break.

> So [1] is really saying get me the first string that is not the empty string or the first non-empty node?
Neither.

It returns the string value of the first *existant* node.
Consider this
( <foo/>,<foo>text</foo>)[1]/string()  => ""

Same with
( string(<foo/>),string(<foo>text</foo>))[1]

The string value of an empty node is "" not ()
Thus the above becomes
( "","text")[1]  => ""


If you want to skip over empty strings you need to get a bit more fancy




-----Original Message-----
From: Ihe Onwuka [mailto:ihe.onwuka at gmail.com] 
Sent: Monday, January 27, 2014 10:20 AM
To: David Lee
Cc: David Carlisle; talk at x-query.com
Subject: Re: [xquery-talk] What does [.] do.

I don't have a preferred order of precedence and no they shouldn't both be there.

So [1] is really saying get me the first string that is not the empty string or the first non-empty node?

On Mon, Jan 27, 2014 at 3:14 PM, David Lee <dlee at calldei.com> wrote:
> I wouldnt do
>
> (readingMaterial|publication)/string()
> or
> (xs:string(readingMaterial),xs:string(publication))[.]
>
> unless you absolutely knew for sure that only 1 existed.
> If both exist you will get 2 strings.
>
> In the first place you get them in document order, in the second case 
> in the order specified.
>
> I would do
>
>    (xs:string(readingMaterial),xs:string(publication))[1]
> or just
>     (readingMaterial,publication)[1]/string()
>
>
> which gives me readingMaterial if it exists, and if it doesnt exist then publication.
> but never both and always in the order of precidence I asked
>
> .
> On 27/01/2014 14:55, Ihe Onwuka wrote:
>> I am using one transformation for two different data sources with two 
>> different schemas.
>>
>> One site may call a resoure readingMaterial another site may call the 
>> same concept a publication, but they are otherwise similar and you 
>> may want to treat them as such.
>>
>> (xs:string(readingMaterial),xs:string(publication))[.]
>>
>
>
>
> I'd probably write that as
>
> (readingMaterial|publication)/string()
>
> or if you know that exactly one of them is always there
>
>
>
> string(readingMaterial|publication)
>
>
> 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.
> ______________________________________________________________________
> __ _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list