Re: [basex-talk] rest:response and status 400/404

2014-04-16 Thread Marco Lettere

Hi Dirk,

8.2.

I'll try the latest.
Thanks,
M.

On 04/15/2014 08:13 PM, Dirk Kirsten wrote:

Hi Marco,

what BaseX version are you using? Did you try with the latest snapshot?

Cheers,
Dirk

On 15/04/14 13:48, Marco Lettere wrote:

Hi Dirk,
this is the output I get when using curl (same as Poster) with response
status 400:


curl -I http://localhost:8984/exists?message=vvv

HTTP/1.1 404 No function found that matches the request.
DBG: message was vvv
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1442
Server: Jetty(8.1.14.v20131031)

whereas if I change the return status to 500


curl -I http://localhost:8984/exists?message=vvv

HTTP/1.1 500 Message wasn't yes!
DBG: message was vvv
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1391
Server: Jetty(8.1.14.v20131031)

Just in case the issue could be related to the combination OS/JAVA:
I'm using Ubuntu "12.04.4 LTS, Precise Pangolin" and running Openjdk 7.
Thanks again and regards,
M.

On 04/13/2014 01:22 PM, Dirk Kirsten wrote:

Hallo Marco,

I tried to reproduce this now, but couldn't manage to do so. curl shows

curl -I http://localhost:8984/exists?message=vvv
HTTP/1.1 400 Message wasn't yes!
DBG: message was vvv
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1391
Server: Jetty(8.1.14.v20131031)

There was no difference when I used another response code (except of
course it returned that return code then).

Are you sure you are setting the correct HEAD request in this Firefox
addon? Of course also this addon could do something incorrectly with the
HEAD request, so you might want to try with another tool like curl or
wget.

If this doesn't help, did you try the latest snapshot (which I used now)?

Cheers,
Dirk

On 11/04/14 17:19, Marco Lettere wrote:

Sorry Dirk,
I should never write mails while in a hurry.
I'll try to restate my question.

This is the code snippet I wanted to use:

declare
%rest:path("/exists")
%rest:HEAD
%rest:query-param("message","{$message}")
function page:exist(
  $message as xs:string)
{

try{
if  ($message = 'yes') then ()
else error(xs:QName("err:ERR"), "Message wasn't yes!")

} catch * {
   
  
  
  
   
}
};

It should return a 400 (Invalid request) whenever an exception is raised
in the implementation of the function. I understand for empty sequences
but it should not impact on the test now.
The point is that if I change the 400 into any other status code I get a
proper response.
With 400 (as it's correctly written in the code now) I get always "404
No function found that matches the request" as the response.

I'm sending my requests with Firefox Poster and they look just like
this: "http://localhost:8984/exists?message=vvv";. For these requests I'm
getting the stacktrace and the responses you can see at the end of the
email.

If I rewrite my query to return for instance 404 or 500 (instead of 400)
I get the same stacktrace but a correct HTTP response "HTTP/1.1 404
Message wasn't yes!".

I hope I could express myself better this time.
Thank you,
M.


org.basex.http.HTTPException: No function found that matches the
request.
  at org.basex.http.HTTPCode.get(HTTPCode.java:55)
  at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:28)
  at org.basex.http.BaseXServlet.service(BaseXServlet.java:58)
[...]
  at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)


  at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)


  at java.lang.Thread.run(Thread.java:744)
_ REQUEST _
[HEAD /exists?message=vvv]@4563057
org.eclipse.jetty.server.Request@45a071
- Host: localhost:8984
- Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: en-US,en;q=0.5
- Connection: keep-alive
- User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0)
Gecko/20100101 Firefox/28.0
- Accept-Encoding: gzip, deflate
_ RESPONSE 
HTTP/1.1 404 No function found that matches the request.
DBG: message was vvv
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1442

java.io.IOException: Closed
  at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140)
  at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:117)
  [...]
  at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)


  at java.lang.Thread.run(Thread.java:744)
java.lang.IllegalStateException: Committed
  at
org.eclipse.jetty.server.Response.resetBuffer(Response.java:1154)
  at org.basex.http.HTTPContext.status(HTTPContext.java:229)
  at org.basex.http.BaseXServlet.service(BaseXServlet.java:65)
  [...]
  at
org.eclipse.jetty.u

Re: [basex-talk] Full text score with or

2014-04-16 Thread Andy Bunce
Hi Christian,

Thanks, that works for me. I always prefer less complex code :-) so it
would be nice if this feature made a return at some point.

Regards
/Andy


On Fri, Apr 11, 2014 at 12:04 PM, Christian Grün
wrote:

> Hi Andy,
>
> as we haven't managed so far to formalize scoring propagation for all
> XQuery expressions, and as we thought that XQuery itself can also be
> used to combine score values, we have recently decided to reduce our
> scoring to the most essential operation (namely, "contains text").
>
> One solution to get this working again is:
>
>   let $data:= (
> red apple,
> blue lagoon,
> fish and chips
>   )
>   for $hit in $data
>   let score $a := $hit/a contains text "red"
>   let score $b := $hit/b contains text "fish"
>   let $score := ($a + $b) div 2
>   where $score
>   return $hit
>
> The advantage is that you can decide by yourself how you want to
> combine scores. The drawback, obviously, is that your code gets more
> complex.
>
> Best,
> Christian
>
>
>
> On Thu, Apr 10, 2014 at 6:27 PM, Andy Bunce  wrote:
> > Hi,
> >
> > I want to score searches with multiple conditions e.g.
> >
> > let $data:=(
> >   red apple,
> >   blue lagoon,
> >   fish and chips)
> >
> > for $hit  score $s  in $data[
> >   a contains text("red")
> > or b contains text("fish")]
> >
> > return $s
> >
> > In 7.8.2 it always returns scores of zero.
> > In version 7.6 it returns numbers like 0.6201145069582775
> 0.4528324252639413
> >
> > Is this bug?
> > Regards
> > /Andy
>


Re: [basex-talk] rest:response and status 400/404

2014-04-16 Thread Marco Lettere

Hello again,
of course I meant 7.8.2 and not 8.2 :-(.
In the meanwhile I've discovered that when I override the rest:response 
with any status different from 20X, I always get the body as text/plain 
even if it's XML.


Example code for a 500 response with a SOAP fault element:

local:errorHTTP($msg as node()) {
   



   ,
   $msg
};

Return:

xmlns:http="http://expath.org/ns/http-client"; status="500" 
message="Server Error">






;
  
  

soapenv:Client
  [...]

  


Is this expected?
Thanks,
Marco.

On 04/16/2014 01:47 PM, Marco Lettere wrote:

Hi Dirk,

8.2.

I'll try the latest.
Thanks,
M.

On 04/15/2014 08:13 PM, Dirk Kirsten wrote:

Hi Marco,

what BaseX version are you using? Did you try with the latest snapshot?

Cheers,
Dirk

On 15/04/14 13:48, Marco Lettere wrote:

Hi Dirk,
this is the output I get when using curl (same as Poster) with response
status 400:


curl -I http://localhost:8984/exists?message=vvv

HTTP/1.1 404 No function found that matches the request.
DBG: message was vvv
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1442
Server: Jetty(8.1.14.v20131031)

whereas if I change the return status to 500


curl -I http://localhost:8984/exists?message=vvv

HTTP/1.1 500 Message wasn't yes!
DBG: message was vvv
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1391
Server: Jetty(8.1.14.v20131031)

Just in case the issue could be related to the combination OS/JAVA:
I'm using Ubuntu "12.04.4 LTS, Precise Pangolin" and running Openjdk 7.
Thanks again and regards,
M.

On 04/13/2014 01:22 PM, Dirk Kirsten wrote:

Hallo Marco,

I tried to reproduce this now, but couldn't manage to do so. curl 
shows


curl -I http://localhost:8984/exists?message=vvv
HTTP/1.1 400 Message wasn't yes!
DBG: message was vvv
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1391
Server: Jetty(8.1.14.v20131031)

There was no difference when I used another response code (except of
course it returned that return code then).

Are you sure you are setting the correct HEAD request in this Firefox
addon? Of course also this addon could do something incorrectly 
with the

HEAD request, so you might want to try with another tool like curl or
wget.

If this doesn't help, did you try the latest snapshot (which I used 
now)?


Cheers,
Dirk

On 11/04/14 17:19, Marco Lettere wrote:

Sorry Dirk,
I should never write mails while in a hurry.
I'll try to restate my question.

This is the code snippet I wanted to use:

declare
%rest:path("/exists")
%rest:HEAD
%rest:query-param("message","{$message}")
function page:exist(
  $message as xs:string)
{

try{
if  ($message = 'yes') then ()
else error(xs:QName("err:ERR"), "Message wasn't yes!")

} catch * {
   
  
  
  
   
}
};

It should return a 400 (Invalid request) whenever an exception is 
raised
in the implementation of the function. I understand for empty 
sequences

but it should not impact on the test now.
The point is that if I change the 400 into any other status code I 
get a

proper response.
With 400 (as it's correctly written in the code now) I get always 
"404

No function found that matches the request" as the response.

I'm sending my requests with Firefox Poster and they look just like
this: "http://localhost:8984/exists?message=vvv";. For these 
requests I'm
getting the stacktrace and the responses you can see at the end of 
the

email.

If I rewrite my query to return for instance 404 or 500 (instead 
of 400)

I get the same stacktrace but a correct HTTP response "HTTP/1.1 404
Message wasn't yes!".

I hope I could express myself better this time.
Thank you,
M.


org.basex.http.HTTPException: No function found that matches the
request.
  at org.basex.http.HTTPCode.get(HTTPCode.java:55)
  at 
org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:28)

  at org.basex.http.BaseXServlet.service(BaseXServlet.java:58)
[...]
  at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) 




  at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) 




  at java.lang.Thread.run(Thread.java:744)
_ REQUEST _
[HEAD /exists?message=vvv]@4563057
org.eclipse.jetty.server.Request@45a071
- Host: localhost:8984
- Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: en-US,en;q=0.5
- Connection: keep-alive
- User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0)
Gecko/20100101 Firefox/28.0
- Accept-Encoding: gzip, deflate
_ RES

[basex-talk] Order of nodes in reversed axes

2014-04-16 Thread José Tomás Atria
Hello all,

I've been looking for an authoritative answer to this, but have been unable
to find one.

I'm trying to reliably get the nearest ancestor of a node. ie with this
test data:

let $test :=
element test {
  attribute id { 4 },
  element test {
attribute id { 3 },
element test {
  attribute id { 2 },
  element test {
attribute id { 1 },
element child { }
  }
}
  }
}

i want an expression that will return node test/@id=1 from child.

Stackoverflow says that this:

$test//child/ancestor-or-self::test[ last() ]

Should work 
(here),
but since I couldn't find any indication to reversed axes being ordered in
the w3c spec for reverse axes in xpath 2.0
(here),
I suspected that this would be implementation dependent, and sure enough,
in BaseX, that expression returns


  

  

  

  


while this

$test//child/ancestor-or-self::test[ 1 ]

​correctly returns


  
​

Is there an authoritative way of getting the nearest ancestor of a given
node? Note that in my actual use case, names are the same, and desired ids
are unknown.

Thanks!

jta

-- 
entia non sunt multiplicanda praeter necessitatem


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread David Rudel
Mr. Atria,
You left out a key element from the answer you got from stack overflow.

Note that Dimitre's response used a filter expression
(path expression) [predicate]

not a simple path expression

The ()s are critical.

$test//child/ancestor-or-self::test[ last() ]

is very different from

($test//child/ancestor-or-self::test)[ last() ]

The ancestor axis is a reverse axis, but when the xpath expression is
complete, the sequence of nodes are then put in document order
regardless of what order the last axis had.

In any event, I don't understand what is wrong with simply
$test/ancestor::element()[1]

Perhaps I don't understand your question (which is simpler than the
Stack Overflow question you linked to). But if you are just looking
for the nearest ancestor element, then it seems that
$test/ancestor::element()[1] should give it to you.


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread David Rudel
More specifically, I don't understand what the difference is between
"nearest ancestor element" and "parent."


On Wed, Apr 16, 2014 at 8:45 PM, David Rudel  wrote:
> Mr. Atria,
> You left out a key element from the answer you got from stack overflow.
>
> Note that Dimitre's response used a filter expression
> (path expression) [predicate]
>
> not a simple path expression
>
> The ()s are critical.
>
> $test//child/ancestor-or-self::test[ last() ]
>
> is very different from
>
> ($test//child/ancestor-or-self::test)[ last() ]
>
> The ancestor axis is a reverse axis, but when the xpath expression is
> complete, the sequence of nodes are then put in document order
> regardless of what order the last axis had.
>
> In any event, I don't understand what is wrong with simply
> $test/ancestor::element()[1]
>
> Perhaps I don't understand your question (which is simpler than the
> Stack Overflow question you linked to). But if you are just looking
> for the nearest ancestor element, then it seems that
> $test/ancestor::element()[1] should give it to you.



-- 

"A false conclusion, once arrived at and widely accepted is not
dislodged easily, and the less it is understood, the more tenaciously
it is held." - Cantor's Law of Preservation of Ignorance.


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread José Tomás Atria
Thank you all for your answers.

I was just tryig to determine if $test/ancestor::element()[1] would be the
correct way of getting the nearest ancestor, as I couldn't find whether
axes were ordered or not in the xpath specification.

Thanks!

ps: Parent doesn't apply, because the relevant node is not always the
parent, but the first node with a given name.


On Wed, Apr 16, 2014 at 2:45 PM, David Rudel  wrote:

> Mr. Atria,
> You left out a key element from the answer you got from stack overflow.
>
> Note that Dimitre's response used a filter expression
> (path expression) [predicate]
>
> not a simple path expression
>
> The ()s are critical.
>
> $test//child/ancestor-or-self::test[ last() ]
>
> is very different from
>
> ($test//child/ancestor-or-self::test)[ last() ]
>
> The ancestor axis is a reverse axis, but when the xpath expression is
> complete, the sequence of nodes are then put in document order
> regardless of what order the last axis had.
>
> In any event, I don't understand what is wrong with simply
> $test/ancestor::element()[1]
>
> Perhaps I don't understand your question (which is simpler than the
> Stack Overflow question you linked to). But if you are just looking
> for the nearest ancestor element, then it seems that
> $test/ancestor::element()[1] should give it to you.
>



-- 
entia non sunt multiplicanda praeter necessitatem


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread David Rudel
I apologize if I'm being dense, but I don't understand how the nearest
ancestor can be anything other than the parent. Could you please give
an example?

I just want to make sure I haven't sent you off with the wrong
expression for your intended usage.

On Wed, Apr 16, 2014 at 8:48 PM, José Tomás Atria  wrote:
> Thank you all for your answers.
>
> I was just tryig to determine if $test/ancestor::element()[1] would be the
> correct way of getting the nearest ancestor, as I couldn't find whether axes
> were ordered or not in the xpath specification.
>
> Thanks!
>
> ps: Parent doesn't apply, because the relevant node is not always the
> parent, but the first node with a given name.
>
>
> On Wed, Apr 16, 2014 at 2:45 PM, David Rudel  wrote:
>>
>> Mr. Atria,
>> You left out a key element from the answer you got from stack overflow.
>>
>> Note that Dimitre's response used a filter expression
>> (path expression) [predicate]
>>
>> not a simple path expression
>>
>> The ()s are critical.
>>
>> $test//child/ancestor-or-self::test[ last() ]
>>
>> is very different from
>>
>> ($test//child/ancestor-or-self::test)[ last() ]
>>
>> The ancestor axis is a reverse axis, but when the xpath expression is
>> complete, the sequence of nodes are then put in document order
>> regardless of what order the last axis had.
>>
>> In any event, I don't understand what is wrong with simply
>> $test/ancestor::element()[1]
>>
>> Perhaps I don't understand your question (which is simpler than the
>> Stack Overflow question you linked to). But if you are just looking
>> for the nearest ancestor element, then it seems that
>> $test/ancestor::element()[1] should give it to you.
>
>
>
>
> --
> entia non sunt multiplicanda praeter necessitatem



-- 

"A false conclusion, once arrived at and widely accepted is not
dislodged easily, and the less it is understood, the more tenaciously
it is held." - Cantor's Law of Preservation of Ignorance.


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread José Tomás Atria
let $test :=
element div0{
  attribute id { 4 },
  element div1 {
attribute id { 3 },
element div1 {
  attribute id { 2 },
  element para {
attribute id { 1 },
element child { }
  }
}
  }
}

I want to get the "smallest" div1 for a given child. this is, the  element.

As far as I've understood the answers given here, reverse axes are ordered
from the context node, so the expression

$test//child/ancestor-or-self::div1[1] will get me what i want, while
$test//child/parent() will give me 

Needless to say, my data is not particularly well behaved :)

Thanks!


On Wed, Apr 16, 2014 at 3:16 PM, David Rudel  wrote:

> I apologize if I'm being dense, but I don't understand how the nearest
> ancestor can be anything other than the parent. Could you please give
> an example?
>
> I just want to make sure I haven't sent you off with the wrong
> expression for your intended usage.
>
> On Wed, Apr 16, 2014 at 8:48 PM, José Tomás Atria 
> wrote:
> > Thank you all for your answers.
> >
> > I was just tryig to determine if $test/ancestor::element()[1] would be
> the
> > correct way of getting the nearest ancestor, as I couldn't find whether
> axes
> > were ordered or not in the xpath specification.
> >
> > Thanks!
> >
> > ps: Parent doesn't apply, because the relevant node is not always the
> > parent, but the first node with a given name.
> >
> >
> > On Wed, Apr 16, 2014 at 2:45 PM, David Rudel  wrote:
> >>
> >> Mr. Atria,
> >> You left out a key element from the answer you got from stack overflow.
> >>
> >> Note that Dimitre's response used a filter expression
> >> (path expression) [predicate]
> >>
> >> not a simple path expression
> >>
> >> The ()s are critical.
> >>
> >> $test//child/ancestor-or-self::test[ last() ]
> >>
> >> is very different from
> >>
> >> ($test//child/ancestor-or-self::test)[ last() ]
> >>
> >> The ancestor axis is a reverse axis, but when the xpath expression is
> >> complete, the sequence of nodes are then put in document order
> >> regardless of what order the last axis had.
> >>
> >> In any event, I don't understand what is wrong with simply
> >> $test/ancestor::element()[1]
> >>
> >> Perhaps I don't understand your question (which is simpler than the
> >> Stack Overflow question you linked to). But if you are just looking
> >> for the nearest ancestor element, then it seems that
> >> $test/ancestor::element()[1] should give it to you.
> >
> >
> >
> >
> > --
> > entia non sunt multiplicanda praeter necessitatem
>
>
>
> --
>
> "A false conclusion, once arrived at and widely accepted is not
> dislodged easily, and the less it is understood, the more tenaciously
> it is held." - Cantor's Law of Preservation of Ignorance.
>



-- 
entia non sunt multiplicanda praeter necessitatem


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread José Tomás Atria
That should have been ancestor::div1[1]. pardon the typo.


On Wed, Apr 16, 2014 at 3:21 PM, José Tomás Atria  wrote:

> let $test :=
> element div0{
>   attribute id { 4 },
>   element div1 {
> attribute id { 3 },
> element div1 {
>   attribute id { 2 },
>   element para {
>  attribute id { 1 },
> element child { }
>   }
> }
>   }
> }
>
> I want to get the "smallest" div1 for a given child. this is, the  id=2> element.
>
> As far as I've understood the answers given here, reverse axes are ordered
> from the context node, so the expression
>
> $test//child/ancestor-or-self::div1[1] will get me what i want, while
> $test//child/parent() will give me 
>
> Needless to say, my data is not particularly well behaved :)
>
> Thanks!
>
>
> On Wed, Apr 16, 2014 at 3:16 PM, David Rudel  wrote:
>
>> I apologize if I'm being dense, but I don't understand how the nearest
>> ancestor can be anything other than the parent. Could you please give
>> an example?
>>
>> I just want to make sure I haven't sent you off with the wrong
>> expression for your intended usage.
>>
>> On Wed, Apr 16, 2014 at 8:48 PM, José Tomás Atria 
>> wrote:
>> > Thank you all for your answers.
>> >
>> > I was just tryig to determine if $test/ancestor::element()[1] would be
>> the
>> > correct way of getting the nearest ancestor, as I couldn't find whether
>> axes
>> > were ordered or not in the xpath specification.
>> >
>> > Thanks!
>> >
>> > ps: Parent doesn't apply, because the relevant node is not always the
>> > parent, but the first node with a given name.
>> >
>> >
>> > On Wed, Apr 16, 2014 at 2:45 PM, David Rudel 
>> wrote:
>> >>
>> >> Mr. Atria,
>> >> You left out a key element from the answer you got from stack overflow.
>> >>
>> >> Note that Dimitre's response used a filter expression
>> >> (path expression) [predicate]
>> >>
>> >> not a simple path expression
>> >>
>> >> The ()s are critical.
>> >>
>> >> $test//child/ancestor-or-self::test[ last() ]
>> >>
>> >> is very different from
>> >>
>> >> ($test//child/ancestor-or-self::test)[ last() ]
>> >>
>> >> The ancestor axis is a reverse axis, but when the xpath expression is
>> >> complete, the sequence of nodes are then put in document order
>> >> regardless of what order the last axis had.
>> >>
>> >> In any event, I don't understand what is wrong with simply
>> >> $test/ancestor::element()[1]
>> >>
>> >> Perhaps I don't understand your question (which is simpler than the
>> >> Stack Overflow question you linked to). But if you are just looking
>> >> for the nearest ancestor element, then it seems that
>> >> $test/ancestor::element()[1] should give it to you.
>> >
>> >
>> >
>> >
>> > --
>> > entia non sunt multiplicanda praeter necessitatem
>>
>>
>>
>> --
>>
>> "A false conclusion, once arrived at and widely accepted is not
>> dislodged easily, and the less it is understood, the more tenaciously
>> it is held." - Cantor's Law of Preservation of Ignorance.
>>
>
>
>
> --
> entia non sunt multiplicanda praeter necessitatem
>



-- 
entia non sunt multiplicanda praeter necessitatem


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread David Rudel
Ah, okay. I didn't catch that you wanted "the nearest ancestor with a
particular name." In that case then I think you are golden. If there
is a chance that the element itself is a div1 element, then you will
want to use ancestor-or-self instead, but otherwise I think you have
it right.

On Wed, Apr 16, 2014 at 9:22 PM, José Tomás Atria  wrote:
> That should have been ancestor::div1[1]. pardon the typo.
>
>
> On Wed, Apr 16, 2014 at 3:21 PM, José Tomás Atria  wrote:
>>
>> let $test :=
>> element div0{
>>   attribute id { 4 },
>>   element div1 {
>> attribute id { 3 },
>> element div1 {
>>   attribute id { 2 },
>>   element para {
>> attribute id { 1 },
>> element child { }
>>   }
>> }
>>   }
>> }
>>
>> I want to get the "smallest" div1 for a given child. this is, the > id=2> element.
>>
>> As far as I've understood the answers given here, reverse axes are ordered
>> from the context node, so the expression
>>
>> $test//child/ancestor-or-self::div1[1] will get me what i want, while
>> $test//child/parent() will give me 
>>
>> Needless to say, my data is not particularly well behaved :)
>>
>> Thanks!
>>
>>
>> On Wed, Apr 16, 2014 at 3:16 PM, David Rudel  wrote:
>>>
>>> I apologize if I'm being dense, but I don't understand how the nearest
>>> ancestor can be anything other than the parent. Could you please give
>>> an example?
>>>
>>> I just want to make sure I haven't sent you off with the wrong
>>> expression for your intended usage.
>>>
>>> On Wed, Apr 16, 2014 at 8:48 PM, José Tomás Atria 
>>> wrote:
>>> > Thank you all for your answers.
>>> >
>>> > I was just tryig to determine if $test/ancestor::element()[1] would be
>>> > the
>>> > correct way of getting the nearest ancestor, as I couldn't find whether
>>> > axes
>>> > were ordered or not in the xpath specification.
>>> >
>>> > Thanks!
>>> >
>>> > ps: Parent doesn't apply, because the relevant node is not always the
>>> > parent, but the first node with a given name.
>>> >
>>> >
>>> > On Wed, Apr 16, 2014 at 2:45 PM, David Rudel 
>>> > wrote:
>>> >>
>>> >> Mr. Atria,
>>> >> You left out a key element from the answer you got from stack
>>> >> overflow.
>>> >>
>>> >> Note that Dimitre's response used a filter expression
>>> >> (path expression) [predicate]
>>> >>
>>> >> not a simple path expression
>>> >>
>>> >> The ()s are critical.
>>> >>
>>> >> $test//child/ancestor-or-self::test[ last() ]
>>> >>
>>> >> is very different from
>>> >>
>>> >> ($test//child/ancestor-or-self::test)[ last() ]
>>> >>
>>> >> The ancestor axis is a reverse axis, but when the xpath expression is
>>> >> complete, the sequence of nodes are then put in document order
>>> >> regardless of what order the last axis had.
>>> >>
>>> >> In any event, I don't understand what is wrong with simply
>>> >> $test/ancestor::element()[1]
>>> >>
>>> >> Perhaps I don't understand your question (which is simpler than the
>>> >> Stack Overflow question you linked to). But if you are just looking
>>> >> for the nearest ancestor element, then it seems that
>>> >> $test/ancestor::element()[1] should give it to you.
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > entia non sunt multiplicanda praeter necessitatem
>>>
>>>
>>>
>>> --
>>>
>>> "A false conclusion, once arrived at and widely accepted is not
>>> dislodged easily, and the less it is understood, the more tenaciously
>>> it is held." - Cantor's Law of Preservation of Ignorance.
>>
>>
>>
>>
>> --
>> entia non sunt multiplicanda praeter necessitatem
>
>
>
>
> --
> entia non sunt multiplicanda praeter necessitatem



-- 

"A false conclusion, once arrived at and widely accepted is not
dislodged easily, and the less it is understood, the more tenaciously
it is held." - Cantor's Law of Preservation of Ignorance.


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread José Tomás Atria
Just for the sake of completion, the authoritative answer is
here
: "The proximity position of a member of a node-set with respect to an axis
is defined to be the position of the node in the node-set ordered in
document order if the axis is a forward axis and *ordered in reverse
document order if the axis is a reverse axis*. The first position is 1."

Ah, okay. I didn't catch that you wanted "the nearest ancestor with a
> particular name." In that case then I think you are golden. If there
> is a chance that the element itself is a div1 element, then you will
> want to use ancestor-or-self instead, but otherwise I think you have
> it right.
>
​
Hopefully, I will never have to find the nearest div for a div in this
collection, the objective was to locate the smallest container for an
infringing non-container (ie, not a div) element. So I think I'm done here.

Thanks!
​
-- 
entia non sunt multiplicanda praeter necessitatem


Re: [basex-talk] Order of nodes in reversed axes

2014-04-16 Thread Liam R E Quin
On Wed, 2014-04-16 at 15:59 -0400, José Tomás Atria wrote:
> Just for the sake of completion, the authoritative answer is
> here

Erm, http://www.w3.org/TR/xpath-30/#id-predicate is closer - XPath 1.0
is rather old and is not really the basis for XQuery.

XQuery 1.0 - http://www.w3.org/TR/xquery/#id-predicates

XQuery 3.0 (just released) -
http://www.w3.org/TR/xquery-30/#id-predicate

Hope this helps.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml