| HTML Tutorials |
|
|
| XML Tutorials |
|
|
| Browser Scripting |
|
|
| Server Scripting |
|
|
| .NET (dotnet) |
|
|
| Multimedia |
|
|
| Web Building |
|
|
| Java Tutorials |
|
|
| Programming Langauges |
|
|
| Soft Skills |
|
|
|
|
XQuery 1.0, XPath 2.0, and XSLT 2.0 shares the same function library.
|
|
XQuery Functions
|
|
XQuery also includes over 100 built-in functions. There are
functions for string values, numeric values, date and time
comparison, node and QName manipulation, sequence manipulation,
Boolean values, and many more. You can also define your own function
in XQuery.
|
|
XQuery Built-in Functions
|
|
The URI of the XQuery function namespace is as follows:
http://www.w3.org/2005/02/xpath-functions The default prefix
for the function namespace is always fn:.
Tip: Functions in XQuery are often called with the fn: prefix,
such as fn:string(). However, since fn: is the default prefix of
the namespace, the function names do not need to be prefixed
when it is called.
|
|
Examples of Function Calls
|
|
A call to the function can appear where an expression may appear. Look at the examples below:
Example 1: In an element as follows
|
|
<name>{uppercase($booktitle)}</name>
|
|
|
Example 2: In the predicate of a path expression which is given below
|
|
doc("bookdetails.xml")/bookstore/book[substring(title,1,5)='Harry']
|
|
|
Example 3: In the let clause
|
|
let $name := (substring($booktitle,1,4))
|
|
|
XQuery User-Defined Functions
|
|
If you cannot find the XQuery function you need, you can write your own functions.
User-defined functionsare always defined in the query or in a separate library.
|
|
Syntax
|
declare function prefix:function_name($parameter AS datatype)
AS returnDatatype
{
(: ...function code here... :)
};
|
|
|
Note that on user-defined functions:
- Use always the declare function keyword
- The name of the function must have prefixed
- The data type of the parameters are mostly the same as
the data types defined in XML Schemas
- The body of the function must be surrounded by curly
braces only
|
|
Example of a User-defined Function Declared in the Query
|
declare function local:minPrice(
$price as xs:decimal?,
$discount as xs:decimal?)
AS xs:decimal?
{
let $disc := ($price * $discount) div 100
return ($price - $disc)
};
(: Below is an example of how to call the function above :)
<minPrice>{local:minPrice($book/price, $book/discount)}</minPrice>
|
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
xquery functions ,xpath functions,xpath function,xpath substring,xpath string,xpath 1.0 functions,xpath 2.0 functions,sql server functions,xpath contains function,xpath count function ,xpath substring before ,xpath string
|
|
| HTML Quizes |
|
|
| XML Quizes |
|
|
| Browser Scripting Quizes |
|
|
| Server Scripting Quizes |
|
|
| .NET (dotnet) Quizes |
|
|
| Multimedia Quizes |
|
|
| Web Building Quizes |
|
|
| Java Quizes |
|
|
| Programming Langauges Quizes |
|
|
| Soft Skills Quizes |
|
|
|