This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 13970 - [UPD] fn:put and transform expressions
Summary: [UPD] fn:put and transform expressions
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Update Facility (show other bugs)
Version: Recommendation
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Jonathan Robie
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-30 12:53 UTC by Tim Mills
Modified: 2014-10-14 09:36 UTC (History)
2 users (show)

See Also:


Attachments

Description Tim Mills 2011-08-30 12:53:55 UTC
Are there any special considerations when mixing fn:put with transform expressions?

Example 1
---------

copy $dummy := <dummy />
modify fn:put(<new-document />, "output.xml")
return local:non-updating-query()

This stores an element in output.xml but also returns the result of executing a non-updating query.  

It seems a little unfortunate that this 'dummy' is required to mix fn:put with a non-updating query - although since this is essentially an expression with side effects, perhaps that's no bad thing.

Example 2
---------

let $original := doc('update.xml')
return
  copy $doc := $original
  modify (insert node <node /> into $doc/nodes, fn:put($doc, "update.xml"))
  return $original

This example reads and writes the same resource.  In XSLT, there is a specific (recoverable) error which mentions a similar situation with xsl:result-document.

[ERR XTRE1500] It is a recoverable dynamic error for a stylesheet to write to an external resource and read from the same resource during a single transformation, whether or not the same URI is used to access the resource in both cases. 

Example 3
---------

copy $doc := doc('update.xml')
modify (insert node <node /> into $doc/nodes, fn:put($doc, "update.xml"))
return (count($doc/nodes/node), count(doc('update.xml')/nodes/node))

Because 'doc' is stable the two calls to doc must return the same result, even though an update has occurred.

Example 4
---------

copy $doc := <a />
modify (fn:put($doc, "update.xml"))
return doc('update.xml')

Does doc('update.xml') see the newly created resource, or the original resource (if we assume one was available)?
Comment 1 Christian Gruen 2012-11-08 00:04:25 UTC
Has there been any more discussion on this issue?

I would even suggest to completely disallow fn:put() functions inside transform expressions in order to reduce the chance of indeterministic, implementation-dependent behavior. For example, in the following example..

  copy $a := <a/> modify fn:put($a, "1") return (),
  copy $b := <b/> modify fn:put($b, "2") return ()

we will have no guarantee if $a or $b will be found in the final result.
Comment 2 Tim Mills 2012-11-08 07:17:41 UTC
The WG hasn't discussed bugs against XQuery Update 1.0 for quite some time due to a focus on XQuery 3.0.
Comment 3 Jonathan Robie 2013-01-15 17:41:21 UTC
The Working Group has decided that it is an error if the modify clause of a transform expression produces a upd:put primitive.
Comment 4 Tim Mills 2014-10-14 09:18:52 UTC
I'm reopening, as I'm unable to find the agreed change in the XQuery Update 3.0 editor's draft.
Comment 5 John Snelson 2014-10-14 09:36:16 UTC
I'm closing this bug again, as the decision is recorded in changes.txt and will be made in the course of time.