[XQuery 1.0: An XML Query Language 2004-7-23 "Chapter 4"

xiaoxiao2021-03-06  44

4 modules and preamble MODULES AND PROLOGS

[1]

Module

:: =

VersionDecl? (Mainmodule | LibraryModule)

[3]

MAINMODULE

:: =

ProLog QueryBody

[4]

LibraryModule

:: =

MODULEDECL PROLOG

[6]

PROLOG

:: =

(SETTER SEPARATOR) * (Import | NamespaceDecl | VARDECL | FUNCTIONDECL) Separetor) *

[7]

Setter

:: =

XmlspaceDecl | DefaultCollationDecl | BaseurideCl | ConstructionDecl | DefaultNamespaceDecl | DefaultOrderingDecl

[8]

Import

:: =

Schemaimport | ModuleImport

[9]

Separator

:: =

";"

[25]

QueryBody

:: =

Expr

[Definition: A query can be assembled by one or more pieces called modules. Each module is a main module or library module. Each module is in turn consisting of one or more components called module resources. [Definition: Module Resource is a XQuery code, which is in line with the module (Module) syntax and can be independently described in the static analysis phase described in 2.2.3 Expression Processings. ]

[Definition: MAIN MODULE) consists of a single module resource containing a query body (Query Body). ] A query has a determined main module. In a master module, the query body can be calculated whose value is the result of the query.

[Definition: The module that does not include query body is called library module. A library module may consist of multiple module resources, each module resource contains a module declaration, and its subsequent preamble. Multiple Modules Resources If named the same target name space in its module declaration, it is considered part of the same library module. A library module cannot be directly calculated; the opposite, it provides functions and variable declarations that can be imported into other modules.

There is no module resource that includes both module declarations and query body.

[Definition: Prolog is a series of declarations and imports to define a session for a modular resource (Module Resource), each declaration or import, following a semicolon. [Definition: Some declarations in the preface are called a setters, because they set certain values ​​that affect the nature of the query processing, such as constructor, sort mode, or default. ] If these givers are present, they must appear in the start of the preface to in any order. A preamble can also include mode and module import, and declarations for named space prefix, variables, and functions. [Definition: Each import mode or module is identified by its target namespace, which is the namespace of objects (such as elements or functions) defined by mode or module. ] [Definition: Query Body, if present, consists of a expression of a specified query result. ] Expression calculation is in 3 Expressions description. A module is only calculated when it has a query body.

4.1 Version Declaring Version Declaration

[2]

VersionDecl

:: =

"xQuery" "Version" Stringliteral Separator

[Definition: Any module resource (module resource) can contain a version declaration. If present, version declarations appear at the beginning of the module resource, and identifies the available XQuery syntax and semantics for module resources (Module Resource). ] The version number "1.0" indicates that the module resource must be processed by an XQuery version 1.0 processor. The version is assumed to be "1.0" if the version declaration does not exist. When a XQuery implementation processes a module resource that is not supported, you must return a static error (Static Error). [Err: XQ0031] The XQuery Working Group is to give this specification number different from "1.0" subsequent version, but this intent does not indicate that the future version of any xQuery is proposed, if it is not necessarily used Specific digital mode.

Below is an example of a version declaration:

XQuery Version "1.0";

4.2 Module Declaration Module Declaration

[5]

Moduledecl

:: =

"Module" "Namespace" ncname "=" Stringliteral Separator

[Definition: Module Declaration) Used to identify a module resource as part of a library module (ilbrary module). A module declares consists of a keyword module and a named space prefix and a serial word containing legitimate URI. [Err: XQ0046] The URI identity library module target namespace, which is named space for all variables and functions imported by this library file. The names of each variable and function declared in the library module must have a namespace URI with the same namespace with the module. [Err: XQ0048]

Any module resource can import a library module in a module import (Module import) specifies the target namespace of the library module to import. When a module imports one or more library modules, the variables and function declarations that are imported modules will be added to the static context and (if available) dynamic context. Below is an example of a module statement:

Module Namespace Math = "http://example.org/math-functions";

4.3 XMLSpace declaration XMLSpace Declaration

[11]

XmlspaceDecl

:: =

"Declare" "Xmlspace" ("preserve" | "strip")

[Definition: XMLSpace Declaration) Controls whether the boundary whitespace is directly preserved when the query is executed during the Query, and the Direct Element Constructors. ] If you specify XMLSpace Preserve, the boundary space is retained. If Xmlspace Strip is specified or there is no XMLSpace declaration, the boundary space is removed (deleted). Further description of the space in the constructor can be found in 3.7.1.4 Whitespace in Element Content.

Below is an example of XMLSpace declaration:

Declare xmlspace preserve;

4.4 Default Collections Declaration Default Collation Declaration

[14]

DEFAULTCOLLATIONDECL

:: =

"declare" "default" "collation" Stringliteral

The preamble will declare a default collation, which is if there is no other specified proofreading, the name of the proofreaded function and the proofread used by the operator. For example, an operator GT acting on a string is defined by a call function fn: Compare that comes with an optional proofreading parameter. Since the operator GT does not specify a school pair, the function fn: Compare is executed in the default proofreading specified in the preface. The default proofread is recognized by a text string that must contain a legal URI. [Err: XQ0046]

If a preamble does not specify a default proof, use Unicode CodePoint Collation (http://www.w3.org/2004/07/xpath-functions/collation/codepoint) unless a different default proof is provided.

Below is an example of a default school pair:

Declare Default Collation

"http://example.org/languages/iceland";

If a preamble specifies more than one default statement, or the specified value cannot be identified as a known school pair, a static error will be triggered. [Err: XQ0038]

4.5 Base URI Declaration Base Uri Declaration

[15]

BaseurideCl

:: =

"Declare" "Base-URI" STRINGLITERALALAL URI Declaration Specifies the base URI (Base URI) nature of the static context, is used when the relative URI within the module resource is parsed. If a preamble is found in a prolog, more than one base URI declaration will trigger a static error [Err: XQ0032]. If a serial word in a base URI declaration does not include a legitimate URI, a static error will be triggered [Err: XQ0046]. Note that the function fn: DOC uses the base URI parsing of the call module to relatively URI.

Below is an example of a base URI statement:

Declare base-uri "http://example.org";

4.6 Constructing CONSTRUCTION DECLATION

[20]

ConstructionDecl

:: =

"declare" "construction" ("preserve" | "strip")

The construction declaration in the preamble (construction deciation) sets the construction mode in the static context to be Preserve or Strip. The behavior of the structural mode is dominated by the element constructor. If the constructor is preserve, a constructor node is XS: AnyType, and the properties of this constructor node and the descendant node maintain its original type. If the constructor is Strip, constructing element nodes, and all child nodes are xdt: united, constructor's attribute type is xdt: untypedatomic. Element constructor is described in 3.7.1 Direct Element Constructionors and 3.7.3.1 Computed Element Constructionors .

The following example shows a constructor:

Declare construction strip;

If a preamble specifies more than one construct declaration, a static error will be triggered [Err: XQ0067]

4.7 Default Name Space Declaration Default Namespace Declaration

[12]

DefaultNamespaceDecl

:: =

("Declare" "Default" "Element") | ("Declare" "default" "Function") "Namespace" StringlIitral

Default Namespace Declarations is used in a prolog to make the QNAME without prefix for easy use. The serial word used in the default namespace declaration must be a legitimate URI or a zero-long string. [Err: XQ0046] The following types of default namespace declarations are supported:

Default Element / Type Namespace declaration declares a namespace URI associated with unfixed elements and type names. This statement is recorded in the static context to default element / type namespace. One preamble can only contain a default element / type namespace declaration. [ERR: XQ0066] If the stringliteral in the default element / type namespace declaration is a zero-long string, the default element / type namespace is set to "None," and an element And typeless unfixed names are considered not in the namespace. The following example shows a declaration of a default element / type namespace: • Declare default element namespace "http://example.org/names";

Default Elements / Type Namespace Declaration Missing Name Space Declaration attribute (Namespace Declaration Attribute) in Direct Element Constructor (Local Namespace Declaration) Overload.

Default Function Namespace Declation Declare a namespace URI associated with the unforquered function name in the function call. This statement is recorded in the static context to the default function namespace. One preamble can only contain one default function namespace declaration [Err: XQ0066]. If a default function namespace declares is a zero loose string, a static error will be triggered [Err: XQ0063]. If there is no default function namespace, the default function namespace is the namespace of the XPath / XQuery function, http://www.w3.org/2004/07/XPATH-Functions (however, this default may be An implementation overload.) The following example illustrates the declaration of the default function namespace:

· DECLARE DEFAULT FUNCTION NAMESPACE

· "Http://example.org/math-functions";

Declare an effect of a default function namespace is that all functions including hidden declarations in the default function namespace, all functions with the original name but no namespace URI. So the function can be called with its original name or its alias - means that the namespace prefix becomes optional. When a function calls uses a function name without prefix, the local name of this function must match with a function (including hidden declaration) in the default function namespace. [Err: XP0017]

There is no prefix attribute name and variable names do not belong to namespaces.

4.8 Default Sorting Declaration Default Order Declaration

[13]

DefaultORDERINGDECL

:: =

"Declare" "Ordered" ("Ordered" | "Default: Default Order Declation) Sets the Sort Mode in Static Context. This sort mode is applied to all expressions in module resources (including preamble (Query Body), if any, unless it is reloaded by an Ordered or unordered expression. If more than one default sorting declaration is found in a preamble (PROLOG), a static error will be triggered [Err: XQ0065].

Sort Mode (ORDERING MODE) affects path expressions, union, interSect, and Except expressions, and FLWOR expressions. If the sort mode is Ordered, the node sequence returned by the path, UNION, INTERSECT, and the Except expression is document order; otherwise, the order of these returning sequences is the implementation-dependent. The effect of sort mode on FLWOR expression is described in 3.8 FlWor Expressions.

The following example shows a default sorting statement:

Declare ordering unordered;

4.9 Mode Import Schema IMPORT

[16]

Schemaimport

:: =

"Import" "Schema" SchemapRefix? Stringliteral ("AT" stringliteral ("," stringliteral *)?

[17]

SchemapRefix

:: =

("Namespace" ncname "=") | ("default" "element" namespace ")

[Definition: Schema Import "The element, attribute, and type definitions are imported from the schema to the mode definition scope (in-scope schema definitions). ] The imported mode is identified by its target namespace (TARGET NAMESPACE). Mode Imports Bind a named space prefix to the imported mode, or declare that the target namespace is imported to the default element / type namespace (DEFAULT Element / Type Namespace) mode will also provide an optional prompt for the mode.

The serial word in a mode import must be a legal URI. [ERR: XQ0046] These string of text specifies the target namespace of the mode to be imported. The serial word next to the keyword is an optional location prompt, which can be interpreted or not processed in a dependent implementation. Multiple location hints is used to indicate more than one possible location to find active resources of mode or multiple component modes.

Specifies a zero-growing string to import mode imports for target namespaces, is considered to import a mode without namespace. Such mode imports may not have to bind a namespace prefix [Err: XQ0057], but it sets the default element / type namespace to "No Namespace", allowing the definition of the imported namespace to be referenced. If the default element / type namespace is not set to "No Namespace", there is no way to reference the definition in import mode without the target namespace. If more than one mode import in the same preamble is imported to specify the same target namespace, a static error error will be thrown. [ERR: XQ0058] If the implementation cannot process a mode import by finding a legal mode with a specified target namespace, static error will be thrown (static error) [Err: XQ0059]. If multiple imported modes or actual resources in multiple in the same mode, the same name is included in the same name of the same name (for example, two definitions, even uniform definitions of the same element name), will trigger a static STATIC Error [Err: XQ0035]. However, the mode imported by the target namespace http://www.w3.org/2001/xmlschema (prefixed XS), does not generate errors, even if the internal types defined in this mode are included in the type definition scope In-Scope Type Definitions.

The following example is an XHTML document import mode, specify its target namespace and its location, and bind prefix XHTML to this namespace:

Import schema namespace xhtml = "http://www.w3.org/1999/xhtml"

AT "http://example.org/xhtml/xhtml.xsd";

The following example is imported into a mode by specifying its target namespace, and makes it a default element / type namespace:

Import Schema Default Element Namespace "http://example.org/Abc";

The following example imports a mode without the target namespace, provides a location prompt, and sets the default element / type namespace to "no namespace" so that the definition in the import mode can be referenced:

Import Schema Default Element Namespace ""

AT "http://example.org/xyz.xsd";

The following example introduces a mode without the target namespace and sets the default element / type namespace to "No Namespace". Since there is no location prompt, it can be used to implement the imported mode.

Import Schema Default Element Namespace ""

4.10 Module Import Module Import

[18]

ModuleImport

:: =

"Import" "Module" ("Namespace" ncname "=")? Stringliteral ("" stringliteral ("," stringliteral *)?

[Definition: MODULE IMPORT) import function declaration and variables from a library module (in-Scope Variables) from a library module import function declaration and variable declaration . ] The module to be imported is determined by its target namespace (TARGET NAMESPACE). The module import will bind a namespace prefix with the target namespace of the imported module, and it will provide an optional prompt for the module resource of the positioned module (Module Resources). The serial word in one module import must be a legal URI. [Err: XQ0046] These string textures specify the target namespace of the imported module. The serial word behind the keyword is an optional positioning prompt, which can be interpreted or not processed in a way in which the implementation-defined is. If the import module consists of multiple module resources (Module Resources), all functions and variable declarations in these module resources will be imported.

If more than one module is imported in a preamble (PROLOG), it will lead a static error (static error) [Err: XQ0047]. If the object namespace of the import module and the import module will be introduced, a static error will be triggered [Err: XQ0056]. If the implementation cannot be found by finding a legitimate module defined by the specified target namespace, a static error will be triggered (static error) [Err: XQ0059]. If multiple modular resources (module resources) that are imported into modules or one imported module, the same name of the same name of the same symbol (for example, two definitions, even uniform definitions) will be included. Static error [Err: XQ0034] [Err: XQ0049].

Module Resource has its own static context. Module import (module import) only import function and variable declarations; not importing other objects from the import module, such as the mode definition scope definitions or static known namespaces. Module imports are not passed - means that importing a module is only available to access to functions and variable declarations directly included in the imported module. For example, if the module A imports module B, and the module B import module C, the module A does not have the power to access the function and variable declared in C. Two modules can be imported with each other.

If the type definition of the import module does not include the definition of the type name of the variable declaration that appears in the import module, the function parameter or the type name of the function returns value, such module import will lead a type error (Type Error ) [ERR: XQ0036]. Import a module that contains a function declaration or variable declaration that is declared in a static context that has been imported into the module is a static error [Err: XQ0037].

To illustrate the above rules, it is assumed that a model defines a type of Triangle. Assuming a library module import this mode, bind its target namespace with the prefix Geometry, and declare a function with the following function signature: Math: Area ($ T as geoetry: Triangle) AS xs: double. If the query wants to use this function, it must pass the library module and import the library file based on the mode. Just import library module does not provide access to Geometry: Triangle type definitions used in the signature of the function area. The following example shows a module import:

Import Module Namespace Math = "http://example.org/math-functions";

4.11 Name Space Declaration Namespace Declaration

[10]

NamespaceDecl

:: =

"declare" "namespace" ncname "=" StringlIitral

[Definition: Namespace declaration) Describes a namespace prefix and associates it with a namespace URI, adds (prefix, URI) to the Static known namespace (STACALLY KNOWN NAMESPACES) collection. ] String text used in the namespace declaration must be a legitimate URI [Err: XQ0046] or a zero-long string. The scope of the namespace declaration runs through the entire query of its declaration, unless it is subjected to a Direct Element Constructor (Namespace Declaration Attribute) or a compute element constructor. The local namespace Declaration is overloaded by Local Namespace Declaration.

The following query is a namespace declaration:

DECLARE NAMESPACE FOO = "http://example.org";

layings

In the query result, the newly created node is in the namespace associated with the namespace URI http://example.org.

A plurality of declarations in the same namespace prefix in a preamble (STATIC Error) [Err: XQ0033]. However, a declaration of a namespace in a preamble can overload a prefix that has been declared in a static context.

Use a QNAME with a named space that has already been declared, will trigger a static error (Static Error). [Err: XP0008]

XQuery has several prefameted namespace prefixes, which are given in static known namespaces before each query is processed. These prefixes can be used without explicit declarations. They are overloaded by Namespace Declarations in the preamble (Namespace Declarations), or is overloaded by Namespace Declaration Attribute (Local Namespace Declarations) (except for prefix) or local namespace declaration XML, it does not have to re-declare). The prefixed namespace prefix is ​​as follows: XML = http://www.w3.org/xml/1998/namespace

XS = http://www.w3.org/2001/xmlschema

XSi = http://www.w3.org/2001/xmlschema-instance

Fn = http://www.w3.org/2004/07/xpath-functions

XDT = http://www.w3.org/2004/07/xpath-datattypes

Local = http://www.w3.org/2004/07/xQuery-local-functions (see 4.13 function decaration.)

Additional predefined namespace prefixes can be added to static known namespaces (STATILY KNOWN NAMESPACES).

The namespace prefix also has a special meaning (it identifies a namespace declarative attribute), and it cannot be re-declared.

Apply the following rules if a skewer part of a namespace declaration is a zero string.

If you support [XML Names 1.1], any existing namespace binded to a given prefix is ​​removed from static known namespaces. This feature provides a way to delete a prefixed namespace prefix like Local.

If the implementation does not support [XML Names 1.1], a static error is thrown. [Err: XQ0053]

A particular implementation supports [XML Names 1.1], is defined by implementation.

When the element or attribute name is compared, if their local part and the namespace URI matches the code point, it is considered the same. The matching of the two names does not have to name the space prefix, as shown in the following example:

Declare namespace xx = "http://example.org";

Let $ i: =

Lentils

RETURN $ I / XX: BING

Although the namespace prefix XX and FOO are different, they are bound to namespace URI "http://example.org". Because xx: bing and foo: bing have the same local name and the same namespace URI, they match. The output of the above query is as follows:

Lentils

4.12 Variable Declaration Variable Declaration

[19]

Vardecl

:: =

"declare" "variable" "$" varName Typedeclaration? ((": =" exprsingle) | "external") [136]

Varname

:: =

Qname

[109]

Typedeclaration

:: =

"AS" Sequencetype

Variable Declaration Add a variable static type to the in-scope variables, or a variable can also be added to variables to variable values. If the magnitude of the variable in the in-scope variables is the same, the same is the same, and there will be a static error (Static Error) [Err: XQ0049].

If the variable declaration contains a type, that type and variable type are added to a static context. If the variable declaration contains an expression that is not an explicit type, the static type of the variable will be inferred by the static type of the expression. If a variable declaration includes both types and an expression, the static type of the expression must be compatible with the declared static statement; otherwise a type error will be triggered [Err: XP0004].

[Definition: If a variable declaration contains an expression, this expression is called an initialization expression. An initialization expression of a given variable must be evaluated before any one references this variable. A static context of an initialization expression includes a function of any location declaration or import in a preamble (ProLog), but it only includes variables that are declared or imported in the preamble or imported and will be initialized. Namespaces. If a initialization expression is not obtained by a ring (for example, its dependent function turns over) the value of the variable to be initialized) without being evaluated, static error [Err: XQ0054].

If the variable declaration contains the keyword External, the external environment must provide a value for the variable before the query can be evaluated. If the external variable declaration also contains a type of declaration, the value provided by the external environment declaration must be consistent with the type of declaration, and the matching rules in 2.4.4 SEQUENCEPE MATCHING (see 2.2.5 CONSITENCY CONSTRAINTS). If an external variable declares does not contain a declared type, the value of the type and the match must be provided by an external environment on request. The static type of such variables is considered to be Item () *.

All variable names declared in a library module must be (when extended) in the target namespace of this library module. [Err: XQ0048] When a library module is imported, the variable declaration of the imported module is added to the in-scope variables in the import module.

Variable names without namespace are not in the namespace. Variable declarations without namespace prefix can only appear in the main module.

The term variable declaration is always a declaration of a variable in prolog. Bind a variable to a value in a query expression (such as FLWOR expression), called variable binding, does not make variables visible to the import module. This is an example of a variable statement:

The following statement also specifies the type and value of a variable. This declaration makes type XS: Integer associated with variable $ x in static context, so that the value 7 is associated with variable $ x in dynamic context.

· DECLARE VARIABLE $ x as xs: integer: = 7;

The following statement specifies a value, but does not specify the type. The static type of the variable is inferred from the static type of its value. In this case, the static type of the variable $ x is inferred from the value 7.5 to XS: Decimal.

· Declare variable $ x: = 7.5;

The following statement specifies the type but does not specify a value. Keywords External Description Variables will be provided by external environments. When evaluating, if the variable in the dynamic context is not type xs: Integer, a type error will be triggered.

· DECLARE VARIABLE $ x as xs: integer external

The following statement has neither specified type and does not specify a value. It only declares that the query relies on the existence of a variable named $ x, and the type and value of this variable will be provided by the external environment. The type is considered to be in the query analysis. During the query evaluation, dynamic contexts must contain the types and values ​​of $ x, and their types and values ​​must be consistent.

Declare Variable $ x external;

4.13 Function Declaration Function Declaration

In addition to the built-in functions illustrated in [XQuery 1.0 and XPath 2.0 functions and operator], XQuery allows users to declare their own functions. Function declaration Specifies the name, parameter name and data type of the parameters, and the data type of the result. All data types are specified using the syntax described in 2.4 Types. The function declaration makes the declared function to be added to the function signature of the module resource it appears (function signatures).

[twenty one]

FunctionDecl

:: =

"declare" "" "" "" "" "" "" "" "" "" "" "external") (ENCLOSEDEXPR | "External")

[twenty two]

Paramlist

:: =

Param ("," param) *

[twenty three]

PARAM

:: =

"$" Varname Typedeclaration?

[109]

Typedeclaration

:: =

"AS" Sequencetype

Function declaration determines a function is a user-defined or an external function (External). [Definition: For a user-defined function, the function declaration includes an expression called a function body, which defines how the function results are calculated from the parameters of the function. ] Static context includes all functions that are declared or imported anywhere in the preamble, but it is only included in the preamble or imported ratio function defined earlier variables and namespaces. [Definition: External functions is a function that is implemented outside the query environment. , For example, an XQuery implementation provides a set of external functions in addition to the core functions illustrated in [XQuery 1.0 and XPath 2.0 functions and operator]. The external function is identified by keyword external. The purpose of the function declaration of an external function is to declare the data type of the function parameters and the results to facilitate the use of or imported this function declared in the type check.

A xQuery implementation may provide a feature, thereby, an external function can be implemented with a host programming language, but this is not required. If such functions are provided, the parameters are passed to an external function, and the function result returns the protocol used by the call query to implement the implementation-defined.

A xQuery implementation may expand the type system of [XQuery 1.0 and XPath 2.0 Data Model] with additional types, design additional types easy to exchange data with host programming language, which can also provide users with such a type of mechanism. For example, a type can be provided that encapsulates an object that is returned by an external function, like a SQL data connection. These additional types (if defined) are considered to be derived from XDT: Anyatomictype.

Each function must be in a namespace - means that each declared function name must be (extension) has a non-empty namespace URI [Err: XQ0060]. Each function name declared in library module must be (extension) in a target namespace of a library module [Err: XQ0048]. If the function name in the function declaration (during extended) is not in any of the following namespaces, a static error will be triggered [Err: XQ0045]:

http://www.w3.org/xml/1998/namespace

http://www.w3.org/2001/xmlschema

http://www.w3.org/2001/xmlschema-instance

http://www.w3.org/2004/07/XPATH-FUNCTIONS

http://www.w3.org/2004/07/xpath-datatypes

If the declared function extension QNAME (Expanded QNAME), and parameter number, the extension QNAME (Expanded QNAME) and parameters of another function in the function signature will lead a static error [Err: XQ0034].

In order to allow the main module to use a declaration function locally locally in the module without defining a new namespace, XQuery predefined to the namespace http://www.w3.org/2004/07/xquery-local-functions Named Space Prefix Local and keep this namespace for defining a local function. If a function parameter is declared using a name but there is no type, its default type is item *. If a function declaration omits the result type, its default result type is item *.

The parameters of a function declaration are considered to be variables of their role domains. A function declaration If there is more than one title parameter, a static error will be triggered [Err: XQ0039]. The type of function parameters can be any type represented by a sequenceType (see 2.4 types).

The following example illustrates a declaration and use of a local function that receives a sequence of an EMPLOYEE element, and a sequence of a DEPT element is returned.

Using a function, prepare a total of employees in Denver.

· DECLARE FUNCTION LOCAL: SUMMARY ($ Emps as Element (Employee) *)

· As Element (DEPT) *

{

· For $ d in Fn: Distinct-Values ​​($ EMPS / DEPTNO)

· Let $ E: = $ Emps [deptno = $ d]

· Return

·

· {$ D}

· {fn: count ($ e)}

· {fn: sum ($ E / SALARY)}

·

}

·

· Local: Summary (FN: DOC ("acme_corp.xml") // EMPLOYEE [location = "denver"])

Conversion of the function parameters to the rules of the parameter type when they declare, and convert the function results into the rules of the result type thereof, in 3.1.5 function calls.

Function declaration can recursively - means that it can reference itself. The mutual recursive function of its function is also allowed. The following example declares a recursive function, calculates the maximum depth of a node level, and calls this function to find the maximum depth of a specific document. In its statement, the user declared the function local: depth call the built-in function EMPTY and Max of the default function namespace.

Find the maximum depth of document called Partlist.xml.

· DECLARE FUNCTION LOCAL: DEPTH ($ E As Node ()) AS XS: Integer

{

· (: A node with no children has depth 1 :)

· (: Otherwise, Add 1 to max depth of children :)

· IF (fn: EMPTY ($ E / *)) THEN 1

· ELSE FN: Max (for $ c in $ E / * RETURN LOCAL: DEPTH ($ C)) 1 ·};

·

· Local: DEPTH (FN: DOC ("partlist.xml"))

Since the constructor function is in a constructor function, the constructor has been effectively declared for each user-defined atom type, if the presence is attempted to declare one of these types, the same expansion The function of qname (expanded QNAME) will trigger a static error (static error) [Err: XQ0034]

note:

in case

XQuery

A future version supports the overload of the function of the user declaration, will generate ambiguity between functions as a function as a parameter and the same name of the same atom value (because a function call is automatically extracted with a function call. Node's atomic value). One such

XQuery

Future version of designers can control function overload by writing appropriate rules, thereby avoiding such ambiguity. Despite this, the user involves this possibility can select the atomic value from the node when the function of the required atom value can be invoked.

转载请注明原文地址:https://www.9cbs.com/read-113197.html

New Post(0)