How to use XQuery in a web page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jkotuby
Forum Newbie
Posts: 7
Joined: Sun Jan 17, 2010 8:37 pm

How to use XQuery in a web page?

Post by jkotuby »

Hi all,
I am a PHP and open source novice. I am trying to use an XML file as a database and XQuery to pull data.. It looks great except for one minor problem. I am sure that I have missed something simple. XQuery has most of the functionality of SQL that I know how to use (at least with MS SQL).

I have read 4 hours worth of tutorials in w3schools.com about XQuery. But there is one question I can't find the answer for.

In what context is XQuery used? Is it used from within a scripting language like PHP or Javascript?

I did a search on "Use xquery in HTML" and came up with this old article snippet.

It shows this example:
=====
You can use {curly braces} to embed XQuery expression inside element constructors:
let $i := 2 return
let $r := <em>Value </em> return
<p>{$r} of 10*{$i} is {10*$i}.</p>

creates:
<p><em>Value </em> of 10*2 is 20.</p>

Here is a more useful example. Assume again that mybook.xml is a <book> that contains some <chapter> elements. Each <chapter> has a <title>. The following will create a simple web page that just lists the titles:

<html>{
let $book := document("mybook.xml")/book
for $ch in $book/chapter
return <h2>{$ch/title)</h2>
}</html>


=====

Which led me to believe I can embed XQuery directly into HTML with the use of curly braces.
I tried creating an HTML page with Dreamwaever and included the above code along with the books.xml file in the same folder and , of course, it did not work.

I really want to use xquery. How do I use it?

Thanks
Post Reply