菜单
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

XML 教程

XML HOME XML Introduction XML How to use XML Tree XML Syntax XML Elements XML Attributes XML Namespaces XML Display XML HttpRequest XML Parser XML DOM XML XPath XML XSLT XML XQuery XML XLink XML Validator XML DTD XML Schema XML Server XML Examples XML Quiz XML Certificate

XML AJAX

AJAX Introduction AJAX XMLHttp AJAX Request AJAX Response AJAX XML File AJAX PHP AJAX ASP AJAX Database AJAX Applications AJAX Examples

XML DOM

DOM Introduction DOM Nodes DOM Accessing DOM Node Info DOM Node List DOM Traversing DOM Navigating DOM Get Values DOM Change Nodes DOM Remove Nodes DOM Replace Nodes DOM Create Nodes DOM Add Nodes DOM Clone Nodes DOM Examples

XPath 教程

XPath Introduction XPath Nodes XPath Syntax XPath Axes XPath Operators XPath Examples

XSLT 教程

XSLT Introduction XSL Languages XSLT Transform XSLT <template> XSLT <value-of> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <choose> XSLT Apply XSLT on the Client XSLT on the Server XSLT Edit XML XSLT Examples

XQuery 教程

XQuery Introduction XQuery Example XQuery FLWOR XQuery HTML XQuery Terms XQuery Syntax XQuery Add XQuery Select XQuery Functions

XML DTD

DTD Introduction DTD Building Blocks DTD Elements DTD Attributes DTD Elements vs Attr DTD Entities DTD Examples

XSD Schema

XSD Introduction XSD How To XSD <schema> XSD Elements XSD Attributes XSD Restrictions XSD Complex Elements XSD Empty XSD Elements-only XSD Text-only XSD Mixed XSD Indicators XSD <any> XSD <anyAttribute> XSD Substitution XSD Example

XSD Data Types

XSD String XSD Date/Time XSD Numeric XSD Misc XSD Reference

Web Services

XML Services XML WSDL XML SOAP XML RDF XML RSS

参考手册

DOM Node Types DOM Node DOM NodeList DOM NamedNodeMap DOM Document DOM Element DOM Attribute DOM Text DOM CDATA DOM Comment DOM XMLHttpRequest DOM Parser XSLT Elements XSLT/XPath Functions

XQuery 函数


XQuery 1.0、XPath 2.0 和 XSLT 2.0 共享相同的函数库。


XQuery 函数

XQuery 基于 XPath 表达式构建。XQuery 1.0 和 XPath 2.0 共享相同的数据模型,并支持相同的函数和运算符。

XPath 运算符

XPath 函数

你也可以在 XQuery 中定义自己的函数。


XQuery 数据类型

XQuery 与 XML Schema 1.0 (XSD) 共享相同的数据类型。

XSD 字符串

XSD 日期

XSD 数字

XSD 杂项


函数调用的示例

函数调用可以出现在表达式可能出现的地方。请看下面的示例

示例 1:在元素中

<name>{upper-case($booktitle)}</name>

示例 2:在路径表达式的谓词中

doc("books.xml")/bookstore/book[substring(title,1,5)='Harry']

示例 3:在 let 子句中

let $name := (substring($booktitle,1,4))


XQuery 用户定义函数

如果你找不到所需的 XQuery 函数,你可以编写自己的函数。

用户定义函数可以在查询中定义,也可以在单独的库中定义。

语法

declare function prefix:function_name($parameter as datatype)
as returnDatatype
{
 ...function code here...
};

关于用户定义函数的说明

  • 使用 declare function 关键字
  • 函数名称必须带有前缀
  • 参数的数据类型与 XML Schema 中定义的数据类型大多相同
  • 函数体必须用大括号括起来

在查询中声明的用户定义函数示例

declare function local:minPrice($p as xs:decimal?,$d as xs:decimal?)
as xs:decimal?
{
let $disc := ($p * $d) div 100
return ($p - $disc)
};

下面是如何调用上述函数的示例

<minPrice>{local:minPrice($book/price,$book/discount)}</minPrice>

×

联系销售

如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com

报告错误

如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com

W3Schools 经过优化,旨在方便学习和培训。示例可能经过简化,以提高阅读和学习体验。教程、参考资料和示例会不断审查,以避免错误,但我们无法保证所有内容的完全正确性。使用 W3Schools 即表示您已阅读并接受我们的使用条款Cookie 和隐私政策

版权所有 1999-2024 Refsnes Data。保留所有权利。W3Schools 由 W3.CSS 提供支持