Discussion:
[xquery-talk] Union of path expressions in XQueryX
Philip Fennell
2014-11-11 14:53:44 UTC
Permalink
Hello,

I'm doing some work with XQueryX and it's not obvious how you create a union of path expressions. Given the example of:

(a | b | c)

which generates the following parse tree, using the java XQuery parser app,:

|QueryList
| Module
| MainModule
| Prolog
| QueryBody
| Expr
| PathExpr
| ParenthesizedExpr
| Expr
| UnionExpr |
| UnionExpr |
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName a
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName b
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName c

there doesn't seem to be anything in XQueryX that actually allows you to construct a UnionExpr.

I've taken to extending XQueryX with a xqx:unionExpr element but seeing the way the parse's output (see above) appears to treat it like a binaryOperatorExpr, with first and second operands, I thought I'd do the following:

<xqx:unionExpr>
<xqx:firstOperand>
<xqx:unionExpr>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>a</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>b</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>c</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>

which, with a tweak to the XQueryX to XQuery transform gives me this:

child::a | child::b | child::c


Would those who have a more intimate knowledge of the XQuery syntax tree and how you would go about implementing this let me know if what I've done is any good.

All feedback, good or bad, would be much appreciated.


Many thanks in advance.


Philip
Josh Spiegel
2014-11-11 17:37:57 UTC
Permalink
Did you see xqx:unionOp?

There is an XQueryX translator here:
http://www.w3.org/2007/01/applets/xqueryApplet.html

You can use it to convert "(a | b | c)” to XQueryX.

Josh
Post by Philip Fennell
Hello,
(a | b | c)
|QueryList
| Module
| MainModule
| Prolog
| QueryBody
| Expr
| PathExpr
| ParenthesizedExpr
| Expr
| UnionExpr |
| UnionExpr |
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName a
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName b
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName c
there doesn't seem to be anything in XQueryX that actually allows you to construct a UnionExpr.
<xqx:unionExpr>
<xqx:firstOperand>
<xqx:unionExpr>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>a</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>b</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>c</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>
child::a | child::b | child::c
Would those who have a more intimate knowledge of the XQuery syntax tree and how you would go about implementing this let me know if what I've done is any good.
All feedback, good or bad, would be much appreciated.
Many thanks in advance.
Philip
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Philip Fennell
2014-11-11 17:51:14 UTC
Permalink
Hello Joe.
Post by Josh Spiegel
Did you see xqx:unionOp?
The xqx:unionOp for (a | b) as XQueryX:

<xqx:unionOp>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>a</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>b</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionOp>

gives me:

(child::a union child::b)

when transformed to XQuery using the supplied XSLT transform(s).

union is part of intersect and except group of instructions, and that's not the same as the pipe operator in a path expression, and it's that that I'm trying to serialise as an XPath (XQuery) expression.
Post by Josh Spiegel
http://www.w3.org/2007/01/applets/xqueryApplet.html
I cannot get the applet to run in any of my browsers on my Mac. Despite some hacking around I cannot get the permissions to allow the Applet to run.


Thanks for the response.

Regards

Philip


On 11 Nov 2014, at 17:37, Josh Spiegel <***@oracle.com<mailto:***@oracle.com>>
wrote:

Did you see xqx:unionOp?

There is an XQueryX translator here:
http://www.w3.org/2007/01/applets/xqueryApplet.html

You can use it to convert "(a | b | c)” to XQueryX.

Josh

On Nov 11, 2014, at 6:53 AM, Philip Fennell <***@marklogic.com<mailto:***@marklogic.com>> wrote:

Hello,

I'm doing some work with XQueryX and it's not obvious how you create a union of path expressions. Given the example of:

(a | b | c)

which generates the following parse tree, using the java XQuery parser app,:

|QueryList
| Module
| MainModule
| Prolog
| QueryBody
| Expr
| PathExpr
| ParenthesizedExpr
| Expr
| UnionExpr |
| UnionExpr |
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName a
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName b
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName c

there doesn't seem to be anything in XQueryX that actually allows you to construct a UnionExpr.

I've taken to extending XQueryX with a xqx:unionExpr element but seeing the way the parse's output (see above) appears to treat it like a binaryOperatorExpr, with first and second operands, I thought I'd do the following:

<xqx:unionExpr>
<xqx:firstOperand>
<xqx:unionExpr>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>a</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>b</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>c</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>

which, with a tweak to the XQueryX to XQuery transform gives me this:

child::a | child::b | child::c


Would those who have a more intimate knowledge of the XQuery syntax tree and how you would go about implementing this let me know if what I've done is any good.

All feedback, good or bad, would be much appreciated.


Many thanks in advance.


Philip






_______________________________________________
***@x-query.com<mailto:***@x-query.com>
http://x-query.com/mailman/listinfo/talk
Josh Spiegel
2014-11-11 18:05:22 UTC
Permalink
When is “|” not the same as “union”? The XPath specification says:

"The union and | operators are equivalent. They take two node sequences as operands and return a sequence containing all the nodes that occur in either of the operands."
http://www.w3.org/TR/xpath20/#doc-xpath-UnionExpr

The applet runs on my mac. Try to update Java and then add “http://www.w3c.org” as a trusted site in “System Preferences” > “Java” > “Security"

Josh
Post by Philip Fennell
Hello Joe.
Post by Josh Spiegel
Did you see xqx:unionOp?
<xqx:unionOp>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>a</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>b</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionOp>
(child::a union child::b)
when transformed to XQuery using the supplied XSLT transform(s).
union is part of intersect and except group of instructions, and that's not the same as the pipe operator in a path expression, and it's that that I'm trying to serialise as an XPath (XQuery) expression.
Post by Josh Spiegel
http://www.w3.org/2007/01/applets/xqueryApplet.html
I cannot get the applet to run in any of my browsers on my Mac. Despite some hacking around I cannot get the permissions to allow the Applet to run.
Thanks for the response.
Regards
Philip
Post by Josh Spiegel
Did you see xqx:unionOp?
http://www.w3.org/2007/01/applets/xqueryApplet.html
You can use it to convert "(a | b | c)” to XQueryX.
Josh
Post by Philip Fennell
Hello,
(a | b | c)
|QueryList
| Module
| MainModule
| Prolog
| QueryBody
| Expr
| PathExpr
| ParenthesizedExpr
| Expr
| UnionExpr |
| UnionExpr |
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName a
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName b
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName c
there doesn't seem to be anything in XQueryX that actually allows you to construct a UnionExpr.
<xqx:unionExpr>
<xqx:firstOperand>
<xqx:unionExpr>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>a</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>b</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>c</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>
child::a | child::b | child::c
Would those who have a more intimate knowledge of the XQuery syntax tree and how you would go about implementing this let me know if what I've done is any good.
All feedback, good or bad, would be much appreciated.
Many thanks in advance.
Philip
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Philip Fennell
2014-11-11 18:15:51 UTC
Permalink
Joe,

When is “|” not the same as “union”? The XPath specification says:

"The union and | operators are equivalent.

Ok, that's good to know, I didn't realise that. So, in order to get the serialisation I want I actually have to extend the transforms to output the pipe '|' character for my particular use case, that's because I'm actually generating XPath expressions for Schematron rules and XForms bindings, and in the case of the latter, XPath 1 I cannot use 'union'.
Post by Josh Spiegel
The applet runs on my mac.
Unfortunately for me, despite being an administrator user, the 'powers that be' have the Java prefs plug-in locked-down so I cannot change the security settings. It's a damned nuisance!


Thanks again for putting my right about union .


Regards

Philip



On 11 Nov 2014, at 18:05, Josh Spiegel <***@oracle.com<mailto:***@oracle.com>>
wrote:

When is “|” not the same as “union”? The XPath specification says:

"The union and | operators are equivalent. They take two node sequences as operands and return a sequence containing all the nodes that occur in either of the operands."
http://www.w3.org/TR/xpath20/#doc-xpath-UnionExpr

The applet runs on my mac. Try to update Java and then add “http://www.w3c.org”<http://www.w3c.xn--org-9o0a/> as a trusted site in “System Preferences” > “Java” > “Security"

Josh


On Nov 11, 2014, at 9:51 AM, Philip Fennell <***@marklogic.com<mailto:***@marklogic.com>> wrote:

Hello Joe.
Post by Josh Spiegel
Did you see xqx:unionOp?
The xqx:unionOp for (a | b) as XQueryX:

<xqx:unionOp>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>a</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>b</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionOp>

gives me:

(child::a union child::b)

when transformed to XQuery using the supplied XSLT transform(s).

union is part of intersect and except group of instructions, and that's not the same as the pipe operator in a path expression, and it's that that I'm trying to serialise as an XPath (XQuery) expression.
Post by Josh Spiegel
http://www.w3.org/2007/01/applets/xqueryApplet.html
I cannot get the applet to run in any of my browsers on my Mac. Despite some hacking around I cannot get the permissions to allow the Applet to run.


Thanks for the response.

Regards

Philip


On 11 Nov 2014, at 17:37, Josh Spiegel <***@oracle.com<mailto:***@oracle.com>>
wrote:

Did you see xqx:unionOp?

There is an XQueryX translator here:
http://www.w3.org/2007/01/applets/xqueryApplet.html

You can use it to convert "(a | b | c)” to XQueryX.

Josh

On Nov 11, 2014, at 6:53 AM, Philip Fennell <***@marklogic.com<mailto:***@marklogic.com>> wrote:

Hello,

I'm doing some work with XQueryX and it's not obvious how you create a union of path expressions. Given the example of:

(a | b | c)

which generates the following parse tree, using the java XQuery parser app,:

|QueryList
| Module
| MainModule
| Prolog
| QueryBody
| Expr
| PathExpr
| ParenthesizedExpr
| Expr
| UnionExpr |
| UnionExpr |
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName a
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName b
| PathExpr
| StepExpr
| AbbrevForwardStep
| NodeTest
| NameTest
| QName c

there doesn't seem to be anything in XQueryX that actually allows you to construct a UnionExpr.

I've taken to extending XQueryX with a xqx:unionExpr element but seeing the way the parse's output (see above) appears to treat it like a binaryOperatorExpr, with first and second operands, I thought I'd do the following:

<xqx:unionExpr>
<xqx:firstOperand>
<xqx:unionExpr>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>a</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>b</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>child</xqx:xpathAxis>
<xqx:nameTest>c</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:unionExpr>

which, with a tweak to the XQueryX to XQuery transform gives me this:

child::a | child::b | child::c


Would those who have a more intimate knowledge of the XQuery syntax tree and how you would go about implementing this let me know if what I've done is any good.

All feedback, good or bad, would be much appreciated.


Many thanks in advance.


Philip






_______________________________________________
***@x-query.com<mailto:***@x-query.com>
http://x-query.com/mailman/listinfo/talk


_______________________________________________
***@x-query.com<mailto:***@x-query.com>
http://x-query.com/mailman/listinfo/talk

Loading...