|
fn:boolean() fn:count() xqe:contains-word() xqe:chr() fn:doc() xqe:document-name() fn:empty() fn:exists() fn:false() fn:name() fn:not() fn:root() fn:string() fn:true() |
XQEngine: Functions and OperatorsThis is a currently short but growing alphabetic list of all functions and operators currently implemented by XQEngine. There are two namespace prefixes in use in this document:
fn:boolean( $arg as item()* ) as xs:booleanReturns the
boolean( () ) -> false (: the empty sequence :)
boolean( false() ) -> false
boolean( "" ) -> false (: a zero-length string :)
boolean( 0 ) -> false (: an integer 0 :)
The Effective Boolean Value of all other argument types evaluates to examples:
boolean( doc( "NoSuchDocumentInTheKnownUniverse" ) ) -> false
(: evals to the empty sequence :)
boolean( (1, 2, 3) ) -> true
fn:count( $arg as item()* ) as xs:integerReturns the number of items in the sequence that examples:
count( (1,2,<emptyTag/>) ) -> 3
count( doc( "bib.xml" )/book ) -> 4
count( ( () ) -> 0
xqe:contains-word($path as node()+, $word as xs:string+, $caseSensitive as xs:boolean?) as node()*The location path$path is evaluated and nodes in the resulting node sequence are checked for instances of the word $word. Words are sequences of non-whitespace characters delimited by whitespace. The default is a case-insensitive search, although the optional boolean argument, $caseSensitive can be used to specify that case is significant. Nodes satisfying the search are returned. An empty sequence will be returned if either $path evaluates to an empty sequence or the sequence is non-empty but no words are found.
Several things are noteworthy here:
NOTA: The signature of this function might change in future to return a boolean value, depending on the final recommendations of the W3C's Full-Text Task Force. A boolean return type makes this function more composable with other XQuery expressions. xqe:chr( $codePoint as xs:integer ) as xs:string?This is a convenience function, one use of which is to allow greater control in formatting serialized output.examples:
1, " ", 2 -> 1 2
1, chr(10), 2 -> 1
2
let $twoLineFeeds := (chr(10), chr(10))
return 1, $twoLineFeeds, 2
-> 1
2
fn:doc( $docUri as xs:string ) as node()?xqe:doc( $docId as xs:integer ) as node()?fn:doc( $docUri as xs:string ) retrieves a document node, given the name that was originally passed to XQEngine.setDocument() or XQEngine.setQuery( "doc(...)" ) to index it. If the document exists but has not already been indexed, it will be. If the evaluation of
$docUri results in an empty sequence ("No Such Document"), the function returns the empty sequence.
examples:
doc( "bib.xml" )//book[ @year = '1992' ]/title
-> <title>Advanced Programming in the Unix environment</title>
doc( 0 )//book[ @year = '1992' ]/title
-> <title>Advanced Programming in the Unix environment</title>
xqe:document-name( $docNode as node()? ) as xs:string?
This function provides similar but not identical functionality to the "Functions and Operators" function,
This function is useful for returning the names of documents contributing to nodes in a hit list. See examples below.
examples:
document-name( doc( "bib.xml" ) ) -> "bib.xml"
doc-name( root( //editor ) ) -> "bib.xml"
for $book in //book
return
(
<title document = "{ doc-name( root( $book )) }">
{ $book/title/text() }
</title>, chr(10)
)
->
<title document="bib.xml">TCP/IP Illustrated</title>
<title document="bib.xml">Advanced Programming in the Unix environment</title>
<title document="bib.xml">Data on the Web</title>
<title document="bib.xml">The Economics of Technology and Content for Digital TV</title>
<title document="book.xml">Data on the Web</title>
fn:empty( $items as item()? ) as xs:booleanIf
examples:
empty( () ) -> true
empty( (1, 2, 3) ) -> false
fn:exists( $items as item()? ) as xs:booleanIf
examples:
exists( () ) -> false
exists( 47 ) -> true
exists( doc( "noSuchDocumentInTheKnownUniverse" ) ) -> false
fn:false( ) as xs:booleanConstructs and returns the boolean valuefalse.
example:
false() -> false
xqe:name( $node as node()? ) as xs:stringReturns the name of a single element or attribute node. Returns a 0-length string if its argument evaluates to the empty sequence or is a node without a name, such as a document or text node. Throws an exception if its argument is neither the empty sequence nor a single node.
examples:
name( //editor ) -> "editor"
name( /bib/book[1]/@year ) -> "year"
name( () ) -> ""
name( //xyzzy ) -> ""
name( doc("bib.xml" )) -> "" (: a "nameless" node type :)
name( //book ) -> InvalidQueryException (: node but not single :)
name( 47 ) -> InvalidQueryException (: not a node at all :)
fn:not( $arg as item()* ) as xs:booleanNegates the Effective Boolean Value of its argument. See fn:boolean().
examples:
not( true() ) -> false not( () ) -> true fn:root( $node as node()? ) as xs:stringReturns the empty sequence if$node evaluates to the empty sequence. Throws an InvalidQueryException if $node does not evaluate to a single node. If $node is the document node, it returns that. Otherwise returns the document node representing the document containing the node.
Useful for accessing a hit node's document node, possibly to derive the name of the owning document. See document-name(). root() currently does not work for constructed nodes.
examples:
doc-name( root(//editor) ) -> "bib.xml"
root( //book ) -> InvalidQueryException (: must be a single node or empty sequence :)
fn:string( $seq as item()* ) as xs:booleanIf$seq is the empty sequence, the zero-length string is returned.
If $seq is a node, the function returns the string-value of the node, as obtained using the dm:string-value accessor defined in the "XQuery 1.0 and XPath 2.0 Data Model" document. For non-node items (ie atomic values), the function casts the item to a string.
examples:
string( //book/author/last ) -> "StevensStevensAbiteboulBunemanSuciu"
string( 1 ) -> "1"
string( () ) ->
xqe:true( ) as xs:booleanConstructs and returns the boolean valuetrue.
examples:
true() -> true
contains-word( doc( "bib.xml" )/bib, "TCP/IP", true() ) (: used as a boolean argument :)
created 25feb04 last updated 25feb04 |