[MarkLogic Dev General] weird xpath behaviour
Geert Josten
geert.josten at dayon.nl
Thu Feb 23 12:07:41 PST 2012
Ha, nice MarkLogic trick. :-)
Other XSLT parsers usually expect a well-formed input document. But then
again, with XML-ER, an empty sequence might just be well-formed..
:-DD
*Van:* general-bounces at developer.marklogic.com [mailto:
general-bounces at developer.marklogic.com] *Namens *Evan Lenz
*Verzonden:* donderdag 23 februari 2012 21:02
*Aan:* MarkLogic Developer Discussion
*Onderwerp:* Re: [MarkLogic Dev General] weird xpath behaviour
Norm Walsh added this quite right correction (forwarding 'cause he's having
email issues):
Evan Lenz <Evan.Lenz at marklogic.com> writes:
In XSLT in MarkLogic, "/" is never short for "collection()/", but then a
context item is
usually defined in XSLT (everywhere, I think, except inside a user-defined
function).
I think you can also get an undefined context item by explicitly passing an
empty sequence as the input and starting the stylesheet at a named template:
xdmp:xslt-invoke("style.xsl", (), (),
<options xmlns="xdmp:eval"><template>{fn:QName("",
"start-here")}</template></options>)
Be seeing you,
norm
*From: *Evan Lenz <evan.lenz at marklogic.com>
*Reply-To: *MarkLogic Developer Discussion <general at developer.marklogic.com>
*Date: *Thu, 23 Feb 2012 11:20:32 -0800
*To: *MarkLogic Developer Discussion <general at developer.marklogic.com>
*Subject: *Re: [MarkLogic Dev General] weird xpath behaviour
Yeah, when there's a context item in 1.0-ml (and always in 1.0), "/" is
short for "root(.) treat as document-node()/", which means it throws an
error when the context item isn't a node (e.g. 42[/x]). In 1.0-ml, if
there's no context item (such as at the top level of a query), then "/" is
short for "collection()/". In 1.0, it would be an error.
In practice, this means that leading "/" can mean two things in 1.0-ml:
- At the top level of a query: "all documents in the database"
- Inside a predicate: "root of the current document"
In XSLT in MarkLogic, "/" is never short for "collection()/", but then a
context item is usually defined in XSLT (everywhere, I think, except inside
a user-defined function).
Evan Lenz
Software Developer, Community
MarkLogic Corporation
community.marklogic.com
*From: *Geert Josten <geert.josten at dayon.nl>
*Reply-To: *MarkLogic Developer Discussion <general at developer.marklogic.com>
*Date: *Thu, 23 Feb 2012 06:55:06 -0800
*To: *MarkLogic Developer Discussion <general at developer.marklogic.com>
*Subject: *Re: [MarkLogic Dev General] weird xpath behaviour
The fact that MarkLogic expands a / at the beginning of an XPath is just a
convenient extension. That a bare / as start within a predicated works like
root()/ is conform spec to my knowledge.
Kind regards,
Geert
*Van:* general-bounces at developer.marklogic.com [mailto:
general-bounces at developer.marklogic.com] *Namens *Szabolcs Illes
*Verzonden:* donderdag 23 februari 2012 15:50
*Aan:* MarkLogic Developer Discussion
*Onderwerp:* Re: [MarkLogic Dev General] weird xpath behaviour
Hi Geert,
That explains it, is it a bug or a feature? ( The same thing works as
expected in eXists … )
Cheers,
Szabolcs
*From:* general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] *On Behalf Of *Geert Josten
*Sent:* 23 February 2012 14:21
*To:* MarkLogic Developer Discussion
*Subject:* Re: [MarkLogic Dev General] weird xpath behaviour
Hi Szabolcs,
Evan pointed out the following to me recently. / at the start of an XPath
expression is interpreted within MarkLogic as ‘collection()/’. A / within a
predicate, however, is not. It is effectively interpreted as ‘root()/ ‘.
Kind regards,
Geert
*Van:* general-bounces at developer.marklogic.com [mailto:
general-bounces at developer.marklogic.com] *Namens *Szabolcs Illes
*Verzonden:* donderdag 23 februari 2012 13:54
*Aan:* general at developer.marklogic.com
*Onderwerp:* [MarkLogic Dev General] weird xpath behaviour
Hi,
I have seen this before, but came across again, so I thought ask this time.
Same/similar xquery but different results:
*Version 1:*
let $ids := /HorseRacingCard/Meeting[@country eq "England" and
AdvancedGoing]/@id
return (/HorseRacing/Meeting[@id = $ids] )[1]
returns expected results.
*Version 2*: Same as 1 but ids vatriable is just inlined
(/HorseRacing/Meeting[@id = /HorseRacingCard/Meeting[@country eq "England"
and AdvancedGoing]/@id ] )[1]
returns nothing [ slow, but that’s expected: ]
Other than Version 2 is NOT optimal since the expression inside the
predicate is evaluated for each sequence item, I guess it should return the
same results.
*Version 3:*
(/HorseRacing/Meeting[@id =* fn:collection()/*HorseRacingCard/Meeting[@country
eq "England" and AdvancedGoing]/@id ] )[1]
Returns expected results and it’s fast, expression is only evaluated once
Can someone shed some light why Version 2 is not returning any results?
Could it be a bug in the optimizer?
Thanks,
Szabolcs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20120223/d1117805/attachment-0001.html
More information about the General
mailing list