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 27630 - Branching based on the XDM value returned by an updating expression
Summary: Branching based on the XDM value returned by an updating expression
Status: NEW
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Update 3.1 (show other bugs)
Version: Working drafts
Hardware: PC Linux
: 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: 2014-12-16 18:10 UTC by John Snelson
Modified: 2015-02-10 11:16 UTC (History)
1 user (show)

See Also:


Attachments

Description John Snelson 2014-12-16 18:10:01 UTC
XQuery Update 3.0 still doesn't have a way to make a decision based on the 
result of an updating expression. All the conditional expressions in the 
language are restricted from having an updating expression in their test 
expressions (if, typeswitch, switch, where etc.). In particular this 
makes it impossible to satisfy the following use case. There is also no way to assign the XDM value of an updating expression to a variable.

Encapsulation Use Case

This use case shows a function which checks if a given username is known 
and logs the event. Both the storage format for usernames and the fact 
that the event is being logged should be hidden from the function's 
caller (encapsulated), since these requirements could change later in 
the development process.

declare %updating function local:check-username($username as xs:string)
    as xs:boolean
{
    let $found := $username = collection()//user/@name
    return (
      insert node
        <access-attempt>
          <timestamp>{fn:current-dateTime()}</timestamp>
          <user-name>{$username}</user-name>
          <access-allowed>{if($found) then "Yes" else "No"}
          </access-allowed>
        </access-attempt>
      into doc("log.xml")/*,
      $found
    )
};

declare variable $username as xs:string external;

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title>Looking up user name</title>
    </head>
    <body>
    {
      if(local:check-username($username)) then
        <p>Welcome, {$username}! Your previous login was:
        {
          doc("log.xml")//access-attempt[username = $username
            and access-allowed = "Yes"]/timestamp/string()
        }
        </p>
      else
        <p>I don't know you!</p>
    }
    </body>
</html>
Comment 1 John Snelson 2014-12-16 18:10:33 UTC
Bug 9026 is related to this.
Comment 2 John Snelson 2014-12-16 18:11:36 UTC
The XQuery WG intends that this should be considered in the XQuery Update 3.1 specification, but no such bugzilla classification currently exists.