Does Jackrabbit support the XPath union (|) operator? - xpath

I am trying to search under 2 different nodes for a specific name. This works
/jcr:root/db067409/libraries/bd0b868d/_x0030_//*[#name="FIRST"]
But when I try to OR it with the second node like so...
/jcr:root/db067409/libraries/bd0b868d/_x0030_//*[#name="FIRST"]|/jcr:root/db067409/libraries/_x0033_78d57e4/_x0031_//*[#name="FIRST"]
I no longer get any search results. Please could someone point out what I've done wrong.
What I'd really like to do is along these lines; if I have /a/b/ID1/VERSION1 and /a/b/ID2/VERSION2 I'd like an xpath something like this /a/b/(ID1/VERSION1 or ID2/VERSION2)//*[#name="some name"].

Answer is no. Unfortunately, it doesnt throw an UnsupportedOperationException like you'd expect. There was an item in Jira but I guess they ignored it as Xpath is now deprecated.
Use JCR_SQL2 if you do need a union.

Edit
This thread indicates that a union-like feature is available in Jackrabbit 2.0, but not earlier.
[Joins] are not possible with JCR
Xpath or JCR-SQL, but with the new query model in JCR 2.0 (JCR-SQL2).
This is supported since CQ 5.3 / CRX 2.0 / Jackrabbit 2.0. Please note
that these joins aren't optimized very much.
Indeed, XPath is deprecated in JCR 2.0.
JCR 1.0 defines a dialect of SQL different from JCR-SQL2, as well as a dialect of XPath. Support for these languages is deprecated.

Related

Choose Xpath version for Saxonc Xpath processor

I just installed Saxonc Python API. All the examples work fine. However, every time I try to evaluate my own expressions, the XPath processor returns an empty sequence. I tested the expressions using Oxygen, and it works well and selects the right node under Xpath 2.0. I think the issue may be that by default, the Xpath processor uses Xpath version 1.0.
Saxonc Python API documentation says that:
Saxon/C provides processing in XSLT 3.0, XQuery 3.0/3.1 and XPath 2.0/3.0/3.1, and Schema validation 1.0/1.1.
However, I can't find how to change the Xpath version.

ElasticSearch 5.6 > 7.x Upgrade, is there an auto_generate_phrase_query Equivalant?

I'm upgrading my codebase's ElasticSearch from 5.6 to 7.x due to some features I'd like to explore.
I'm currently using GoLang & "github.com/olivere/elastic/v5" specifically.
However, auto_generate_phrase_query has been depreciated, and AutoGeneratePhraseQueries no longer works on v7 ("github.com/olivere/elastic/v7").
I've read to use explicit quoted queries, what is the equivalent to that in olivere? is there no setting i can set to true/false in ES when making requests to achieve this? Must i explicitly wrap my queries in quotation marks? Surely there must be a proper way to do this...
I found this: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-query-string-query.html
which states use [type=phrase] instead
In Olivere, i can set this via: Type("phrase"); is this a sufficient alternative?
The closest thing was actually using Phrase Queries. For anyone in the future coming back to find an answer.

Is there an XPath equivilent for Linq to XML?

I have been using Linq to XML for a few hours and while it seems lovely and powerful when it comes to loops and complex selections, it doesn't seem so good for situations where I just want to select a single node value which XPath seems to be good at.
I may be missing something obvious here but is there a way to use XPath and Linq to XML together without having to parse the document twice?
You can still use XPath, with the XPathEvaluate, XPathSelectElement and XPathSelectElements extension methods. You can also call CreateNavigator to create an XPathNavigator.

is it possible to specify a OR in a Xpath in a XSD?

I want to be able to guarantee uniqueness for two types of elements : MainQuestion and AlternateQuestion.
In the select query for my xsd:key, can I specify something that would do "//MainQuestion or //AlternateQuestion"? Someone told me that something like this existed, but it seems that XSD only supports a subset of the XPath syntax...
You should be able to use | as usual:
//MainQuestion | //AlternateQuestion
the syntax is indeed restricted - it is roughly the same as restrictions for template patterns in XSLT 1.0, but in addition to that it cannot have any filters in path steps. However, | is explicitly listed as supported.
Supporting Pavel's answer that you can use "|" in an XPath in XML Schema.
XML Schema supports a subset of XPath (which I think of as "fake XPath"). What it supports is explicitly stated in the spec. You have to trace through a few sections to find it. This is a link to the exact section:
http://www.w3.org/TR/xmlschema-1/#c-selector-xpath
Do you have tried the or ?
http://w3schools.com/xpath/xpath_operators.asp

What's the difference between XSL Pattern and XPath in syntax?

I'm updating codes to use MSXML6.0 from MSXML3.0.
However, I noticed that, for MSXML3.0, the default "SelectionLanguage" is "XSL Pattern", while MSXML6.0 only support XPath.
I have concerns that this change would introduce differences in the query syntax.
Can somebody list the difference of syntax between these two syntax?
The one thing that has tripped me up is selecting the first node in a node set. For example, we'd been using MSXML 3.0 (which uses XSLPattern) and has queries like this:
/root/book[0]
This query was supposed to select the first book. This works with XSLPattern. But with XPath, this is correct:
/root/book[1]
So when I switched us to using MSXML 6.0, which uses correct XPath, all those queries with "[0]" stopped working.
Update:
I just found this link that talks some more about XSLPattern and XPath:
MSDN Magazine: MSXML 3.0 Supports XPath 1.0, XSLT 1.0, XDR, and SAX2
http://msdn.microsoft.com/en-us/magazine/cc302348.aspx
Update #2:
Here's the W3C Spec on XSLT which includes XSL Patterns:
http://www.w3.org/TR/1998/WD-xsl-19981216.html#AEN376
Update #3
Here's another post that describes the same thing I mentioned above:
http://www.eggheadcafe.com/software/aspnet/29579789/xml-parsing.aspx
XSL Pattern, if I remember correctly, was a selection language like XPath but was implemented by Microsoft before XPath was standardised (possibly even created). I don't think anyone even has anything that documents XSL Pattern any more. You can basically forget about it and concentrate on XPath. It has the same purpose but is supported and standardised.
XSL Patterns appear to be part of WD-XSL, "working draft XSL", which means versions predating the XSL recommendation (1999), which differ significantly from the final 1.0 version.
Microsoft has the relevant info on "XSL Patterns". Here's a quote from the section XPath 1.0 APIs:
MSXML 2.0 provides support for XSL Patterns, the precursor to XPath 1.0. The notion of an XML addressing language was introduced into the original W3C XSL Working Drafts (http://www.w3.org/TR/1998/WD-xsl-19981216.html) and called XSL Patterns. MSXML 2.0 implements the XSL Patterns language as described in the original XSL specification with a few minor exceptions.
MSXML 3.0 provides support for the legacy XSL Patterns syntax as well as XPath 1.0.
XPath, in my experience, is much easier to get your head around. I avoid XSL like the plague if I can. But you are right, the syntax is very different, so if you want to switch from XSL to XPath you have some work ahead of you. I cannot explain the differences easily, but this tutorial should give you some idea of what XPath is about:
http://www.w3schools.com/XPath/xpath_examples.asp

Resources