Menu

#32 document-uri function does not yield useful result

Sedna_(current)
open
5
2013-03-22
2009-08-18
No

Synopsis:
The document-uri function does not yield a useful result for non-standalone documents (i.e. when the document is stored in a Sedna collection).

Scenario:
Load standalone document with LOAD "rose.xml" "rose"
Create collection with CREATE COLLECTION "flowers"
Load non-standalone document with LOAD "rose.xml" "rose" "flowers"
Query document-uri of both documents and same result is returned.

document-uri( doc( "rose")) -> returns rose

document-uri( doc( "rose", "flowers")) -> returns rose

Problem:
When a document is a member of a collection, document-uri should return both the collection name and the document name.

Work-around:
One can discover the name of the collection that contains a specific document with the following code but it is felt that this might be rather inefficient :

~~~~~
let $rose-doc := doc( "rose", "flowers")
let $coll-names := for $coll in doc( "$collections")/collections/collection return string( $coll/@name)
return $coll-names[collection( .)[. is $rose-doc]]
~~~~~~

Cheers
Justin Johansson

p.s. Thank you, Sedna Team, for all your excellent work in addressing the various issues/bugs that I've raised recently.

Discussion

  • Ivan Shcheklein

    Ivan Shcheklein - 2009-08-18

    Hi Justin, thank you for this bug report.

    We know about this issue and we have some ideas on how to implement usefull document URIs in Sedna.

     
  • Justin Johansson

    Thanks for your response Ivan.
    I guess the main concern you would have thought about is implementing this so as to be compliant with XQuery 1.0, the relevant part of the spec being:

    "In the case of a document node $D returned by the fn:doc function, or a document node at the root of a tree containing a node returned by the fn:collection function, it will always be true that either fn:document-uri($D) returns the empty sequence, or that the following expression is true: fn:doc(fn:document-uri($D)) is $D. It is implementation-defined whether this guarantee also holds for document nodes obtained by other means, for example a document node passed as the initial context node of a query or transformation."

    So once you decide upon a scheme for implementing Sedna document URI's, you will need to align the code to reflect this in each of these XQuery functions: fn:doc, fn:doc-available, fn:document-uri and fn:collection.

    Then having done that you will probably want to remove your custom 2-parameter document() function which of course is not a standard XQuery function. Actually I always get confused between doc() and document() functions. The latter, of course, is specific to XSLT whilst doc() is common to XQuery 1.0 and XPath 2.0 Functions.

    Would you be considering as well if the database name should be part of your document URI? That would possibly be quite a useful feature to have.

    Cheers
    Justin Johansson

     
  • Ivan Shcheklein

    Ivan Shcheklein - 2012-10-19
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -17,9 +17,11 @@
     Work-around:
     One can discover the name of the collection that contains a specific document with the following code but it is felt that this might be rather inefficient :
    
    +~~~~~
     let $rose-doc := doc( "rose", "flowers")
     let $coll-names := for $coll in doc( "$collections")/collections/collection return string( $coll/@name)
     return $coll-names[collection( .)[. is $rose-doc]]
    +~~~~~~
    
     Cheers
     Justin Johansson
    
     

Anonymous
Anonymous

Add attachments
Cancel