It is nice to be able to do a temporary switching of the input node-context
from the current xupdate-document to "some-other-nodes" to build our
resulting node-set. This is very like the document()-function in xpath, the
for-each tag and apply-templates tag in xslt change the input node-context
and the value-of tag in xslt selects string values from nodes while
xsl:copy-of copies entire nodes/node-sets.

If we look at xslt, we have one or more source documents generating one new
result document.
In the database case we have one or more source nodes that update nodes in
the db.
Each xml-document is in fact a database, and every database can be seen as
an xml-document.
So the real difference between xslt and xupdate lies in the specification of
where the result nodes are to be placed.

The more I think about it, the more I believe that xslt and xupdate should
be identical, with the small difference that in xupdate the result is not an
entirely new document but modifications to an existing document (or
database).

This difference is easily covered by using the <xupdate:update>, the
<xupdate:insert-before>, etc. where one in xslt simply would have had an
<xsl:element> or a literal result element. In xslt version 1.1 one can also
produce multiple output documents with the <xsl:document> tag. This is a
very nice analogy to xupdate producing (or modifying) nodes (each node is
sort of a document) in a database (which is sort of a document, too, only
bigger).

There might however exist a need to build up a temporary node-set to be used
as an input node-context somewhere in the processing. This is however
addressed in xslt 1.1, with variables and parameters being assigned node-set
values.

Conclusion: no special select is needed, the functionality already exists in
xslt in a xsl:value-of.
The nodelist tag is not needed either, one simply builds variables that hold
node-sets (as in xslt 1.1) and iterate through them with a for-each or an
apply-templates, perhaps building new variables with node-sets to resolve
relations.

I attach an example where the processing is very xslt-like, except that the
result element is instead a modification specified by an <xupdate:update>

Sorry, Tom, I didn't understand what you were doing in your example, else I
would have rewritten that with xslt-like syntax.

/tobe

> -----Ursprungligt meddelande-----
> Från: Tom Bradford [mailto:[EMAIL PROTECTED]
> Skickat: den 15 september 2001 21:38
> Till: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Ämne: XSelect thoughts and ramblings
> 
> 
> Yesterday, I threw together some ideas for a quick and dirty extension
> of the XUpdate language that would provide support for relational
> queries against multiple collections.  It would be a easy to use,
> relatively easy to implement alternative to XQuery, which becomes more
> of a monstrosity every time I look at it.
> 
> Like I said, I threw it together quickly, so it's nowhere close to
> usable.  I'd very much like feedback for refining it more. 
> 
> The file XSelect.txt is attached.
> 
> Thanks,
> Tom
> 
> -- 
> Tom Bradford  The dbXML Group, L.L.C.  http://www.dbxmlgroup.com/
> Desktop, Laptop, Settop, Palmtop.  Can your XML database do that?
> 

How to update the database from an input-document (here i increase the stock from an 
invoice received from my supplier):

<xupdate:modifications>
  <x:for-each select="document(invoice.xml)/orderline">
<!-- now the node in context is an orderline from invoice.xml -->
    <x:variable name="productid" select="@productid"/> <!-- needed because of 
context-change -->
    <x:variable name="no-items" select="@no-items"/> <!-- needed because of 
context-change -->
    <xupdate:update select="/stock/[EMAIL PROTECTED]">
<!-- here I guess the node in context is /stock/product -->
      <xupdate:attribute name="no-in-stock">
        <x:value-of select="@no-in-stock + $no-items"/>
      </xupdate:attribute>
    </xupdate:update>
  </x:for-each>
</xupdate:modifications>

But it would be even nicer to do this with a template:

<xupdate:modifications>
  <x:template name="increase-stock">
    <x:parameter name="productid"/>
    <x:parameter name="no-items"/>
    <xupdate:update select="/stock/[EMAIL PROTECTED]">
<!-- here I guess the node in context is the selected /stock/product -->
      <x:attribute name="no-in-stock"><x:value-of select="@no-in-stock + 
$no-items"/></x:attribute>
    </xupdate:update>
  </x:template>

  <x:for-each select="document(invoice.xml)/orderline">
<!-- now the node in context is an orderline from invoice.xml -->
    <x:call-template name="increase-stock">
      <x:with-param name="productid" select="@productid"/>
      <x:with-param name="no-items" select="@no-items"/>
    </x:call-template>
  </x:for-each>
</xupdate:modifications>

Hmm, what happens if the select for <xupdate:update> turns up empty?

Reply via email to