How to test element existence in XQuery

Hello People

I am sorry that I have to disturb you with this simple question but how to test element existence in new Tamino XQuery. I am especially interested in FLWOR queries with where clause (since they are better optimized at the moment). I thought the task was easy but Tamino confused me a bit.

So let’s take two documents:
2. IL-96

I run some queries with this data:

for $doc in input()/Document[AllProducts or Product=‘IL-96’]
return $doc
Result: 1 and 2

for $doc in input()/Document
where $doc[AllProducts or Product=‘IL-96’]
return $doc
Result: 1 and 2

for $doc in input()/Document
where $doc/AllProducts or $doc/Product='IL-96’
return $doc
Result: only 2

I wonder may be I understand something wrong. This XQuery can be so difficult under some circumstances. So are all these queries mean the same or have different semantic (especially the last one)?

By the way the following query returns me document 1!
for $doc in input()/Document
where $doc/AllProducts
return $doc

Thanks in advance!

Hello Alexander,
the 3rd query must also deliver both documents.
In my v4.1.1 an v4.1.4 it works correctly.
Please check with the support.

Best regards

It only happens if Product element has index.
I’ve attached my schema.
sagsis.tsd (1.53 KB)

I also need this feature.
Couple days ago I wrote the following code:

// xQuery_2_Object can be a query to Attribute or an Element
public boolean doesObjectExists(String xQuery_2_Object, TXMLObjectAccessor accessor) {

try {

TXQuery query = TXQuery.newInstance(xQuery_2_Object);
TResponse response = accessor.xquery( query );

return response.hasQueryContent();

catch (TXQueryException e) {
JOptionPane.showMessageDialog(this, e, “TXQueryException”, JOptionPane.ERROR_MESSAGE);
return false;