← Back to team overview

zorba-coders team mailing list archive

[Bug 1005995] Re: fn:path() should support fragments as well as documents

 

13.9 fn:path

Summary
Returns a path expression that can be used to select the supplied node relative to the root of its containing document.

Signatures
fn:path() as xs:string?
fn:path($arg as node()?) as xs:string?
Properties
The one-argument form of this function is ·deterministic·, ·context-dependent·, and ·focus-dependent·.

The two-argument form of this function is ·deterministic·, ·context-
independent·, and ·focus-independent·.

Rules
The behavior of the function if the argument is omitted is exactly the same as if the context item (.) had been passed as the argument.

If $arg is the empty sequence, the function returns the empty sequence.

If $arg is a document node, the function returns the string "/".

Otherwise, the function constructs a string that consists of a sequence
of steps, one for each ancestor-or-self of $arg other than the root
node. This string is prefixed by "Q{http://www.w3.org/2005/xpath-
functions}root()" if the root node is not a document node. Each step
consists of the character "/" followed by a string whose form depends on
the kind of node selected by that step, as follows:

For an element node, Q{uri}local[position], where uri is the namespace URI of the node name or the empty string if the node is in no namespace, local is the local part of the node name, and position is an integer representing the position of the selected node among its like-named siblings.
For an attribute node:
if the node is in no namespace, @local, where local is the local part of the node name
otherwise, @Q{uri}local, where uri is the namespace URI of the node name, and local is the local part of the node name
For a text node: text()[position] where position is an integer representing the position of the selected node among its text node siblings
For a comment node: comment()[position] where position is an integer representing the position of the selected node among its comment node siblings
For a processing-instruction node: processing-instruction(local)[position] where local is the name of the processing instruction node and position is an integer representing the position of the selected node among its like-named processing-instruction node siblings
For a namespace node:
If the namespace node has a name: namespace::prefix, where prefix is the local part of the name of the namespace node (which represents the namespace prefix).
If the namespace node has no name (that is, it represents the default namespace): namespace::*[Q{http://www.w3.org/2005/xpath-functions}local-name()=""]
Examples
let $e :=

fn:parse-xml('<?xml version="1.0"?>
<p xmlns="http://example.com/one"; xml:lang="de" author="Friedrich von Schiller">
Freude, schöner Götterfunken,<br/>
Tochter aus Elysium,<br/>
Wir betreten feuertrunken,<br/>
Himmlische, dein Heiligtum.</p>')
         
The expression fn:path($e) returns '/'.

The expression fn:path($e/*:p) returns '/Q{http://example.com/one}p[1]'.

The expression fn:path($e/*:p/@xml:lang) returns
'/Q{http://example.com/one}p[1]/@Q{http://www.w3.org/XML/1998/namespace}lang'.

The expression fn:path($e/*:p/@author) returns
'/Q{http://example.com/one}p[1]/@author'.

The expression fn:path($e/*:p/*:br[2]) returns
'/Q{http://example.com/one}p[1]/Q{http://example.com/one}br[2]'.

The expression fn:path($e//text()[starts-with(normalize-space(),
'Tochter')]) returns '/Q{http://example.com/one}p[1]/text()[2]'.

let $emp :=

            <employee xml:id="ID21256">
               <empnr>E21256</empnr>
               <first>John</first>
               <last>Brown</last>
            </employee>
         
The expression fn:path($emp) returns 'Q{http://www.w3.org/2005/xpath-functions}root()'.

The expression fn:path($emp/@xml:id) returns 'Q{http://www.w3.org/2005
/xpath-functions}root()/@Q{http://www.w3.org/XML/1998/namespace}id'.

The expression fn:path($emp/empnr) returns 'Q{http://www.w3.org/2005
/xpath-functions}root()/Q{}empnr'.

-- 
You received this bug notification because you are a member of Zorba
Coders, which is the registrant for Zorba.
https://bugs.launchpad.net/bugs/1005995

Title:
  fn:path() should support fragments as well as documents

Status in Zorba - The XQuery Processor:
  New

Bug description:
  Modify fn:path to add support for fragments

To manage notifications about this bug go to:
https://bugs.launchpad.net/zorba/+bug/1005995/+subscriptions


References