What is the Venn diagram for XPath, XQuery, and XQuery Update? - xpath

Note: in all of the following, when I refer to "XQuery" I mean the latest version of XQuery. Ditto for XQuery Update.
[True or False] XQuery is a superset of XPath. That is, the XQuery language consists of all the stuff in XPath plus more.
Eek! I didn't specify the version of XPath.
[True or False] XQuery is a superset of XPath 1.0
[True or False] XQuery is a superset of XPath 2.0
[True or False] XQuery is a superset of XPath 3.0
[True or False] XQuery is a superset of XPath 3.1
[True or False] XQuery Update is a superset of XQuery.

XQuery 3.1 is a superset of XPath 3.1. Or, more generally, for a given version of XQuery, it is a superset of the same version of XPath.
XQuery Update extends XQuery. XQuery Update remains at version 3.0 and has not been updated to account for XQuery 3.1's support for maps and arrays.

Related

PMD Xpath to check presence Relational Expression

Wrote below Xpath , which to i want extend to include "<", ">=" etc.
//RelationalExpression[#Image=">" and
descendant :: PrimaryExpression/PrimaryPrefix/Name[#Image!="ABC" and #Image!="PQR"]]
Below rule does not give correct result,
//RelationalExpression[#Image=">" or #Image="<" and
descendant :: PrimaryExpression/PrimaryPrefix/Name[#Image!="ABC" and #Image!="PQR"]]
Any solution to correct the check?

Is there are more concise way than using position() for multiple conditions in XPath?

In XPath you can use *[position()=1 or position()=last()] to get both the first and last matching node. However, if you want either just the first or last node you can use *[1] or *[last()] respectively. Trying to use something like *[1 or last()] selects all nodes. Is there a more concise way of joining the conditions?
Short answer: No. There is no more concise way than [position()=1 or position()=last()] that make sense for this purpose.
Regarding this predicate that you tried [1 or last()] :
number 0 translated to boolean False and the rest translated to True.
last() returns position index of the last element in context
Given above rules, this kind of predicate expressions [1 or last()] always translated to [True or True] which evaluates to True, that's why you get all nodes using this predicate.

Logical expression evaluation in Xpath

I have an XPATH expression of the following sort that's expected to return a boolean value:
xs:boolean(expression1 or expression2 or expression3)
If expression1 returns true, would the other expressions be evaluated?
In any case could any one point me to examples of how complex logical expressions are written efficiently in XPATH?
BTW: I am running the XPATH on MarkLogic.
In XPath 1.0 it's defined that the expressions are evaluated in order, left to right, until one of them returns true.
But the presence of xs:boolean (which is redundant) in your expression suggests you are using XPath 2.0, and XPath 2.0 processors are allowed to evaluate the subexpressions in any order. This is to allow database-style optimization: one of the subexpressions might be much faster to execute (or more likely to return true) than the others, perhaps because of database indexes, so an optimizer will evaluate that one first. But any decent optimizer will stop evaluation after the first expression that evaluates to "true".
I can't tell you specifically what MarkLogic does.
For anyone else trying this, the "or" operator in XPath must be lower-case.
In light of Michael Kay's comments on optimization, I can't say for sure whether MarkLogic chooses expression to evaluate first or goes left to right, but you can see how a particular XPath is evaluated. In Query Console (usually localhost:8000/qconsole), type in an expression, click the Profile tab, and Run.
//foo[xs:boolean(1 = 1 or 2 = 3)]
The profile tab shows that "1 = 1" is evaluated and "2 = 3" is not.

Simplifying an xpath expression used by selenium

I've got the following XPath expression that I call from selenium (technically, from splinter, which is calling selenium):
//label[text()="data"]/following-sibling::div/input|//label[text()="data"]/following-sibling::div/textarea
Is there a way to simplify this expression? The following doesn't work in selenium, although it seems to work in AquaPath:
//label[text()="data"]/following-sibling::div/(input|textarea)
Try:
//label[text()="data"]/following-sibling::div/*[self::input or self::textarea]
Whenever there are many (more than 3 alternatives), an expression like this is considerably shorter:
someExpr/*[contains('|name1|name2|name3|name4|', concat('|',name(), '|'))]

Nokogiri, different results of xpath in JRuby

I am getting different results from the same xpath expression in nokogiri when using ruby and jruby,
In ruby the following xpath expression returns a node while in jruby it returns a nodeset:
parent = node.xpath("./ancestor::node()[name(.) = 'div' or name(.) = 'p'][1]")
Has anybody else noticed similar behaviour?
There seems to be a difference between how libxml2 (used in the MRI Nokogiri) and whatever library the pure-Java version uses in how they handle predicates that match only one node. You should report this to the nokogiri-talk mailing list.

Resources