Gannholm Torbjörn wrote:
> Sorry, Tom, I didn't understand what you were doing in your example, else I
> would have rewritten that with xslt-like syntax.

In the past couple of days, I've refined the syntax more, so the example
would look like this:

<x:query name="test" xmlns:x="http://www.xmldb.org/XUpdate";>
   <x:parameter name="id"/>
   <x:select col="/db/invoices" match="/[EMAIL PROTECTED]">
      <x:for match="products/product" action="replace">
          <x:variable name="id" match="@id"/>
          <x:select col="/db/products" match="/[EMAIL PROTECTED]" />
      </x:for>
   </x:select>
</x:query>

The query element is simply the wrapper.

The parameter element establish a parameter context.  Parameters must be
provided by the calling context.  The original example had an error in
it... parameters can't have values in the query itself.

The first select is the top level select.  From the collection
/db/invoices, retrieve all invoice documents that have an id attribute
of the value provided in the parameter id.

The for element says for each document returned, replace all produce
elements under the products element.

The variable element says to create a scoped variable called id, and
assign the value of the product's id element to it.

The sub select pulls in all documents from the collection /db/products
that have an id attribute whose value is equal to the value of the id
variable.

A resulting document might like like this:

<invoice id="12345">
   <header>
      <customer id="9543"/>
      <address ship-to="9543-1"/>
      <address bill-to="9543-2"/>
   </header>
   <products>
      <product id="10001">
         <name>Nerf Cannon</name>
         <description>A Nerf death cannon</description>
         <price type="usd">39.99</price>
      </product>
      <product id="10009">
         <name>Nerf Cannon Ammo</name>
         <description>Ammo for the Nerf death cannon</description>
         <price type="usd">8.99</price>
      </product>
   </product>
</invoice>

In a real invoice, you'd never want to include the actual product
information... This would let you perform a query that expands it for
external processing.  Obviously, you can define a more complex query
that expands the customer, and address records.  The point in XSelect is
not to transform documents, but to easily link/expand them.

-- 
Tom Bradford  The dbXML Group, L.L.C.  http://www.dbxmlgroup.com/
Desktop, Laptop, Settop, Palmtop.  Can your XML database do that?
----------------------------------------------------------------------
Post a message:         mailto:[EMAIL PROTECTED]
Unsubscribe:            mailto:[EMAIL PROTECTED]
Contact administrator:  mailto:[EMAIL PROTECTED]
Read archived messages: http://archive.xmldb.org/
----------------------------------------------------------------------

Reply via email to