Discussion:
[xquery-talk] What does [.] do.
Ihe Onwuka
2014-01-27 11:46:37 UTC
Permalink
As in ('','8')[.]

What is it called and where is it documented
Ihe Onwuka
2014-01-27 11:49:46 UTC
Permalink
I get it... it's a filter expression. Like it.
Post by Ihe Onwuka
As in ('','8')[.]
What is it called and where is it documented
Ghislain Fourny
2014-01-27 13:59:04 UTC
Permalink
Hi Ihe,

You are right that it is a filter expression.

However, I think [.] is not very common in "real world" code, except maybe for very precise use cases (like filtering out empty strings, etc). Usually you would put either a position or a boolean predicate inside a filter expression -- not just a context item expression.

What [.] does, if I am not missing anything, is that it only keeps:
1. Numerics equal to their position in the left-hand-side sequence
and
2. Non-numerics that have an Effective Boolean Value of true, like non-empty strings, nodes, the true boolean, etc.

Example:
(1, 2, 4, 3, 5, "", "foo", <a/>, true, false)[.]

returns

1 (position matches)
2 (position matches)
5 (position matches)
foo (EBV = true)
<a/> (EBV = true)
true (EBV = true)

I hope it helps.

Kind regards,
Ghislain
--
Dr. Ghislain Fourny
Software Architect

28msec Inc.

http://www.28.io/
http://twitter.com/28msec
Post by Ihe Onwuka
As in ('','8')[.]
What is it called and where is it documented
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Michael Kay
2014-01-27 14:45:19 UTC
Permalink
Post by Ghislain Fourny
Hi Ihe,
You are right that it is a filter expression.
However, I think [.] is not very common in "real world" code, except maybe for very precise use cases (like filtering out empty strings, etc). Usually you would put either a position or a boolean predicate inside a filter expression -- not just a context item expression.
1. Numerics equal to their position in the left-hand-side sequence
and
2. Non-numerics that have an Effective Boolean Value of true, like non-empty strings, nodes, the true boolean, etc.
I mention on p648 of my XSLT /XPath book that the expression

some $s in $S satisfies CONDITION

is equivalent to

exists(for $s in $S return boolean(CONDITION)[.])

though I don't suppose that really counts as a use case.

I think the only case I've used in anger is probably count(tokenize($x, ' ')[.]) which eliminates the zero-length tokens that can arise at the start and/or end of the sequence.

Michael Kay
Saxonica
Ihe Onwuka
2014-01-27 14:55:16 UTC
Permalink
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))[.]

when you know they are mutually exclusive in your document but you
want to process them in the same way.
Post by Michael Kay
Post by Ghislain Fourny
Hi Ihe,
You are right that it is a filter expression.
However, I think [.] is not very common in "real world" code, except maybe for very precise use cases (like filtering out empty strings, etc). Usually you would put either a position or a boolean predicate inside a filter expression -- not just a context item expression.
1. Numerics equal to their position in the left-hand-side sequence
and
2. Non-numerics that have an Effective Boolean Value of true, like non-empty strings, nodes, the true boolean, etc.
I mention on p648 of my XSLT /XPath book that the expression
some $s in $S satisfies CONDITION
is equivalent to
exists(for $s in $S return boolean(CONDITION)[.])
though I don't suppose that really counts as a use case.
I think the only case I've used in anger is probably count(tokenize($x, ' ')[.]) which eliminates the zero-length tokens that can arise at the start and/or end of the sequence.
Michael Kay
Saxonica
Michael Sokolov
2014-01-27 15:04:38 UTC
Permalink
What I have usually seen in that case is:

(xs:string(readingMaterial),xs:string(publication))[1]

which allows for prioritization in case there are actually both for some
unforeseen reason
Post by Ihe Onwuka
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))[.]
when you know they are mutually exclusive in your document but you
want to process them in the same way.
Post by Michael Kay
Post by Ghislain Fourny
Hi Ihe,
You are right that it is a filter expression.
However, I think [.] is not very common in "real world" code, except maybe for very precise use cases (like filtering out empty strings, etc). Usually you would put either a position or a boolean predicate inside a filter expression -- not just a context item expression.
1. Numerics equal to their position in the left-hand-side sequence
and
2. Non-numerics that have an Effective Boolean Value of true, like non-empty strings, nodes, the true boolean, etc.
I mention on p648 of my XSLT /XPath book that the expression
some $s in $S satisfies CONDITION
is equivalent to
exists(for $s in $S return boolean(CONDITION)[.])
though I don't suppose that really counts as a use case.
I think the only case I've used in anger is probably count(tokenize($x, ' ')[.]) which eliminates the zero-length tokens that can arise at the start and/or end of the sequence.
Michael Kay
Saxonica
_______________________________________________
http://x-query.com/mailman/listinfo/talk
David Carlisle
2014-01-27 15:08:23 UTC
Permalink
Post by Ihe Onwuka
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.
________________________________________________________________________
Ihe Onwuka
2014-01-27 15:14:53 UTC
Permalink
Post by David Carlisle
Post by Ihe Onwuka
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)
I started with some variation of the union version (without the
string) and was getting error messages.

I can't remember what they were now and I've had to reboot my machine
so can't go back and look.
David Lee
2014-01-27 15:14:39 UTC
Permalink
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

.
Post by Ihe Onwuka
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.
David Carlisle
2014-01-27 15:18:16 UTC
Permalink
Post by David Lee
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.
Yes sure, but same is true of the rather more opaque original
(xs:string(readingMaterial),xs:string(publication))[.]
I was trying to get same result (modulo , | change) :-)

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.
________________________________________________________________________
Ihe Onwuka
2014-01-27 16:07:41 UTC
Permalink
Having given it a bit more than a moments thought I prefer [.] because
it makes it explicit a filtering operation is going on .

I think any opacity is consequent on the syntax - not the semantic .
Post by David Carlisle
Post by David Lee
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.
Yes sure, but same is true of the rather more opaque original
(xs:string(readingMaterial),xs:string(publication))[.]
I was trying to get same result (modulo , | change) :-)
David
________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
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.
________________________________________________________________________
Ihe Onwuka
2014-01-27 15:19:58 UTC
Permalink
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?
Post by David Lee
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
.
Post by Ihe Onwuka
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
________________________________________________________________________
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.
________________________________________________________________________
_______________________________________________
http://x-query.com/mailman/listinfo/talk
David Lee
2014-01-27 15:34:48 UTC
Permalink
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:***@gmail.com]
Sent: Monday, January 27, 2014 10:20 AM
To: David Lee
Cc: David Carlisle; ***@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?
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
.
Post by Ihe Onwuka
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
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.
______________________________________________________________________
__ _______________________________________________
http://x-query.com/mailman/listinfo/talk
Ihe Onwuka
2014-02-07 10:25:13 UTC
Permalink
Post by Michael Kay
I think the only case I've used in anger is probably count(tokenize($x, ' ')[.]) which eliminates the zero-length tokens that can arise at the start and/or end of the sequence.
slight variation

tokenize($url,'/')[.][last()]

that gets me the last bit of a url irrespective of whether it ends with a /
Ihe Onwuka
2014-02-10 09:59:56 UTC
Permalink
Post by Ghislain Fourny
Hi Ihe,
You are right that it is a filter expression.
However, I think [.] is not very common in "real world" code, except maybe for very precise use cases (like filtering out empty strings, etc). Usually you would put either a position or a boolean predicate inside a filter expression -- not just a context item expression.
1. Numerics equal to their position in the left-hand-side sequence
and
2. Non-numerics that have an Effective Boolean Value of true, like non-empty strings, nodes, the true boolean, etc.
(1, 2, 4, 3, 5, "", "foo", <a/>, true, false)[.]
returns
1 (position matches)
2 (position matches)
5 (position matches)
foo (EBV = true)
<a/> (EBV = true)
true (EBV = true)
In Zorba it does - but is that right?

In Saxon 9.3.0.5 it gives

Error on line 1 of *module with no systemId*:
XPDY0002: The context item for axis step child::true is undefined
The context item for axis step child::true is undefined

In eXist it gives

err:XPDY0002 Undefined context sequence for 'child::{}true' [at line
1, column 34, source: String]
Michael Kay
2014-02-10 11:14:09 UTC
Permalink
Post by Ihe Onwuka
Post by Ghislain Fourny
Hi Ihe,
You are right that it is a filter expression.
However, I think [.] is not very common in "real world" code, except maybe for very precise use cases (like filtering out empty strings, etc). Usually you would put either a position or a boolean predicate inside a filter expression -- not just a context item expression.
1. Numerics equal to their position in the left-hand-side sequence
and
2. Non-numerics that have an Effective Boolean Value of true, like non-empty strings, nodes, the true boolean, etc.
(1, 2, 4, 3, 5, "", "foo", <a/>, true, false)[.]
returns
1 (position matches)
2 (position matches)
5 (position matches)
foo (EBV = true)
<a/> (EBV = true)
true (EBV = true)
In Zorba it does - but is that right?
It's right if there is a context item, which is context-dependent....

For true and false in this example, you probably meant true() and false().

Michael Kay
Saxoinca
Post by Ihe Onwuka
In Saxon 9.3.0.5 it gives
XPDY0002: The context item for axis step child::true is undefined
The context item for axis step child::true is undefined
In eXist it gives
err:XPDY0002 Undefined context sequence for 'child::{}true' [at line
1, column 34, source: String]
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Ihe Onwuka
2014-02-10 11:20:24 UTC
Permalink
Post by Michael Kay
Post by Ihe Onwuka
Post by Ghislain Fourny
Hi Ihe,
You are right that it is a filter expression.
However, I think [.] is not very common in "real world" code, except maybe for very precise use cases (like filtering out empty strings, etc). Usually you would put either a position or a boolean predicate inside a filter expression -- not just a context item expression.
1. Numerics equal to their position in the left-hand-side sequence
and
2. Non-numerics that have an Effective Boolean Value of true, like non-empty strings, nodes, the true boolean, etc.
(1, 2, 4, 3, 5, "", "foo", <a/>, true, false)[.]
returns
1 (position matches)
2 (position matches)
5 (position matches)
foo (EBV = true)
<a/> (EBV = true)
true (EBV = true)
In Zorba it does - but is that right?
It's right if there is a context item, which is context-dependent....
For true and false in this example, you probably meant true() and false().
No. I am aware of that distinction. I was quoting the results obtained
from the example that was quoted.

***@ihe-ThinkPad-T410:~/film$ zorba -q '(1, 2, 4, 3, 5, "", "foo",
<a/>, true, false)[.]'
(no URI):1,41: static warning [zwarn:ZWST0008]: "false": has been
deprecated; use "fn:false()" instead
(no URI):1,35: static warning [zwarn:ZWST0008]: "true": has been
deprecated; use "fn:true()" instead
<?xml version="1.0" encoding="UTF-8"?>
1 2 5 foo<a/>truei
Michael Kay
2014-02-10 19:15:00 UTC
Permalink
Post by Ihe Onwuka
No. I am aware of that distinction. I was quoting the results obtained
from the example that was quoted.
<a/>, true, false)[.]'
(no URI):1,41: static warning [zwarn:ZWST0008]: "false": has been
deprecated; use "fn:false()" instead
(no URI):1,35: static warning [zwarn:ZWST0008]: "true": has been
deprecated; use "fn:true()" instead
Those warnings appear to be telling you that Zorba is applying a non-standard meaning to the names true and false, and is warning you that it is doing so. If so you are right, it's not conformant.

Michael Kay
Saxonica

Loading...