XQuery: how to determine scope?

Issues related to W3C XQuery.
Zearin
Posts: 107
Location: College Park, MD, United States

XQuery: how to determine scope?

Tue Aug 02, 2011 5:15 pm

(Wow, am I really the first poster in the XQuery forum?)

So, conceptually I understand XQuery. And I like its philosophy.

(XSL was my first love, though. :wink: XQuery just has a different “feel”, which has a very different mindset when programming. I want to explore that…and if I’m really lucky, start using eXist seriously instead of just screwing around now and then.)

But one thing that has always driven me absolutely crazy is trying to figure out when I’m in “XQuery” scope versus “XML” scope. I can’t figure it out!

  • Sometimes there are curly braces, sometimes there aren’t.
  • When inserting a variable or function call into XML, does it get enclosed in curly braces? If you’re already inside open braces, do you (a) close them, insert the value, then re-open them and continue writing XML, or (b) stick in the $value and keep going?

I have checked tutorials and guides. I really have. I’m obviously missing something right in front of me—something most people have no problem with.

Anybody who can demystify
-- Zearin
Zearin
Posts: 107
Location: College Park, MD, United States

Re: XQuery: how to determine scope?

Tue Aug 02, 2011 5:17 pm

Whoops…looks like I forgot to delete a partial thought. Ignore that last sentence fragment. Sorry! Couldn’t seem to find an “edit” button…
-- Zearin
adrian
Posts: 2326

Re: XQuery: how to determine scope?

Tue Aug 02, 2011 5:50 pm

Hello,

Zearin wrote:(Wow, am I really the first poster in the XQuery forum?)
The forum is getting reorganized. It's the first time we have an XQuery forum, so most XQuery topics from the past are scattered around. Soon we will gather these topics and move them here.


Well the rule is simple: If you're in XML context(between tags or inside a tag) and want to evaluate an XQuery expression, you have to use curly braces.

Note that you can even have nested braces.
<XML>{
XQuery <XML>{XQuery}</XML> XQuery
}</XML>

e.g.

Code: Select all

<test>{
let $tst := "a test"
return <testing attr="{$tst}">{$tst}</testing>
}</test>

This yields:

Code: Select all

<test>
   <testing attr="a test">a test</testing>
</test>


If you're in XML context and you don't use curly braces, the content is considered XML text:

Code: Select all

<test>{
let $tst := "a test"
return <testing attr="$tst">$tst</testing>
}</test>

This yields:

Code: Select all

<test>
   <testing attr="$tst">$tst</testing>
</test>

No evaluation of the XQuery code.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “XQuery”

Who is online

Users browsing this forum: No registered users and 0 guests