📄 xpath_functions.asp
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XPath, XQuery, and XSLT Function Reference</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<link rel="stylesheet" type="text/css" href="../stdtheme.css" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<a name="top"></a>
<table cellpadding="0" cellspacing="0" width="100%" bgcolor="#808080">
<tr>
<td width="234" valign="top">
<a href="../default.htm"><img src="../images/w3default80.jpg" border="0" alt="W3Schools" /></a>
</td>
<th valign="middle" align="left" class="right">
<iframe style="background-color:#808080" src="../banners/bannerframe.asp@adpartner=xmlspy" height="90" width="728"
marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
Your browser does not support inline frames or is currently configured not to display inline frames.
</iframe>
<br /></th>
</tr>
</table>
<table style="margin-left:1px" width="800px" border="0" cellpadding="0" cellspacing="2">
<tr>
<td width="137" class="content" valign="top"><br />
<a class="left" href="../default.asp" target="_top">
<img src="../images/homeicon.gif" border="0" alt="home" /></a>
<a class="left" href="../default.asp" target="_top">
<b>HOME</b></a>
<br /><br />
<b>XPath Tutorial</b><br />
<a class="left" target="_top" href="default.asp" >XPath HOME</a><br />
<a class="left" target="_top" href="xpath_intro.asp" >XPath Intro</a><br />
<a class="left" target="_top" href="xpath_nodes.asp" >XPath Nodes</a><br />
<a class="left" target="_top" href="xpath_syntax.asp" >XPath Syntax</a><br />
<a class="left" target="_top" href="xpath_axes.asp" >XPath Axes</a><br />
<a class="left" target="_top" href="xpath_operators.asp" >XPath Operators</a><br />
<a class="left" target="_top" href="xpath_examples.asp" >XPath Examples</a><br />
<a class="left" target="_top" href="xpath_summary.asp" >XPath Summary</a><br />
<br />
<b>References</b>
<br />
<a class="left" target="_top" href="xpath_functions.asp" style='font-weight:bold;'>XPath Functions</a><br />
<br />
<b>Selected Reading</b><br />
<a class="left" target="_top" href="../browsers/browsers_stats.asp">Web Statistics</a><br />
<a class="left" target="_top" href="../site/site_glossary.asp">Web Glossary</a><br />
<a class="left" target="_top" href="../hosting/default.asp">Web Hosting</a><br />
<a class="left" target="_top" href="../quality/default.asp">Web Quality</a><br /><br />
<a class="left" target="_top" href="../forum/default.asp">W3Schools Forum</a><br /><br />
<a class="left" target="_top" href="../about/about_helping.asp">Helping W3Schools</a><br /><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3440800076797949";
/*LeftLinkUnit*/
google_ad_slot = "4854527104";
google_ad_width = 120;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="../../pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
<td valign="top">
<table style="border: 1px solid gray" width="100%" bgcolor="#FFFFFF" border="0" cellpadding="5" cellspacing="0">
<tr>
<td>
<h1>XPath, XQuery, and XSLT Functions</h1>
<a href="xpath_summary.asp"><img border="0" src="../images/btn_previous.gif" width="100" height="20" alt="Previous" /></a>
<a href="default.asp"><img border="0" src="../images/btn_next.gif" width="100" height="20" alt="Next" /></a>
<hr />
<p class="intro">The following reference library defines the functions required for XPath 2.0, XQuery 1.0 and XSLT 2.0.</p>
<hr />
<h1>Functions Reference</h1>
<table border="0">
<tr>
<td valign="top">
<ul>
<li><a href="#accessor">Accessor</a></li>
<li><a href="#error">Error and Trace</a></li>
<li><a href="#numeric">Numeric</a></li>
<li><a href="#string">String</a></li>
</ul>
</td>
<td valign="top">
<ul>
<li><a href="#anyuri">AnyURI</a></li>
<li><a href="#boolean">Boolean</a></li>
<li><a href="#datetime">Duration/Date/Time</a></li>
<li><a href="#qname">QName</a></li>
</ul>
</td>
<td valign="top">
<ul>
<li><a href="#node">Node</a></li>
<li><a href="#sequence">Sequence</a></li>
<li><a href="#context">Context</a></li>
</ul>
</td>
</tr>
</table>
<p>The default prefix for the function namespace is fn:, and the URI is:<br />
http://www.w3.org/2005/02/xpath-functions.</p>
<h3><a name="accessor">Accessor Functions</a></h3>
<table class="ex" cellspacing="0" border="1" width="100%" id="table1">
<tr>
<td width="45%" valign="top"><b>Name</b></td>
<td width="55%" valign="top"><b>Description</b></td>
</tr>
<tr>
<td valign="top">fn:node-name(<i>node</i>)</td>
<td valign="top">Returns the node-name of the argument node</td>
</tr>
<tr>
<td valign="top">fn:nilled(<i>node</i>)</td>
<td valign="top">Returns a Boolean value indicating whether the argument
node is nilled</td>
</tr>
<tr>
<td valign="top">fn:data(<i>item.item,...</i>)</td>
<td valign="top">Takes a sequence of items and returns a sequence of atomic
values</td>
</tr>
<tr>
<td valign="top">fn:base-uri()<br />
fn:base-uri(<i>node</i>)</td>
<td valign="top">Returns the value of the base-uri property of the current
or specified node </td>
</tr>
<tr>
<td valign="top">fn:document-uri(<i>node</i>)</td>
<td valign="top">Returns the value of the document-uri property for the
specified node</td>
</tr>
</table>
<h3><a name="error">Error and Trace Functions</a></h3>
<table class="ex" cellspacing="0" border="1" width="100%" id="table2">
<tr>
<td width="45%" valign="top"><b>Name</b></td>
<td width="55%" valign="top"><b>Description</b></td>
</tr>
<tr>
<td valign="top">fn:error()<br />
fn:error(<i>error</i>)<br />
fn:error(<i>error,description</i>)<br />
fn:error(<i>error,description,error-object</i>)</td>
<td valign="top">Example: error(fn:QName('http://example.com/test',
'err:toohigh'), 'Error: Price is too high')<p>Result: Returns
http://example.com/test#toohigh and the string "Error: Price is too high" to
the external processing environment</td>
</tr>
<tr>
<td valign="top">fn:trace(<i>value,label</i>)</td>
<td valign="top">Used to debug queries</td>
</tr>
</table>
<h3><a name="numeric">Functions on Numeric Values</a></h3>
<table class="ex" cellspacing="0" border="1" width="100%" id="table7">
<tr>
<td width="45%" valign="top"><b>Name</b></td>
<td width="55%" valign="top"><b>Description</b></td>
</tr>
<tr>
<td valign="top">fn:number(<i>arg</i>)</td>
<td valign="top">Returns the numeric value of the argument. The argument
could be a boolean, string, or node-set<p>Example: number('100')<br />
Result: 100</td>
</tr>
<tr>
<td valign="top">fn:abs(<i>num</i>)</td>
<td valign="top">Returns the absolute value of the argument<p>Example:
abs(3.14)<br />
Result: 3.14</p>
<p>Example: abs(-3.14)<br />
Result: 3.14</td>
</tr>
<tr>
<td valign="top">fn:ceiling(<i>num</i>)</td>
<td valign="top">Returns the smallest integer that is greater than the number argument<p>
Example: ceiling(3.14)<br />
Result: 4</td>
</tr>
<tr>
<td valign="top">fn:floor(<i>num</i>)</td>
<td valign="top">Returns the largest integer that is not greater than the number argument<p>
Example: floor(3.14)<br />
Result: 3</td>
</tr>
<tr>
<td valign="top">fn:round(<i>num</i>)</td>
<td valign="top">Rounds the number argument to the nearest integer<p>Example: round(3.14)<br />
Result: 3</td>
</tr>
<tr>
<td valign="top">fn:round-half-to-even()</td>
<td valign="top">Example: round-half-to-even(0.5)<br />
Result: 0
<p>Example: round-half-to-even(1.5)<br />
Result: 2</p>
<p>Example: round-half-to-even(2.5)<br />
Result: 2</p></td>
</tr>
</table>
<h3><a name="string">Functions on Strings</a></h3>
<table class="ex" cellspacing="0" border="1" width="100%" id="table8">
<tr>
<td width="45%" valign="top"><b>Name</b></td>
<td width="55%" valign="top"><b>Description</b></td>
</tr>
<tr>
<td valign="top">fn:string(<i>arg</i>)</td>
<td valign="top">Returns the string value of the argument. The argument
could be a number, boolean, or node-set<p>Example: string(314)<br />
Result: "314"</td>
</tr>
<tr>
<td valign="top">fn:codepoints-to-string(<i>int,int,...</i>)</td>
<td valign="top">Returns a string from a sequence of code points<p>Example:
codepoints-to-string(84, 104, 233, 114, 232, 115, 101)<br />
Result: 'Th閞鑣e' </td>
</tr>
<tr>
<td valign="top">fn:string-to-codepoints(<i>string</i>)</td>
<td valign="top">Returns a sequence of code points from a string<p>Example:
string-to-codepoints("Th閞鑣e")<br />
Result: 84, 104, 233, 114, 232, 115, 101</td>
</tr>
<tr>
<td valign="top">fn:codepoint-equal(<i>comp1,comp2</i>)</td>
<td valign="top">Returns true if the value of comp1 is equal to the value of
comp2, according to the Unicode code point collation
(http://www.w3.org/2005/02/xpath-functions/collation/codepoint), otherwise
it returns false</td>
</tr>
<tr>
<td valign="top">fn:compare(<i>comp1,comp2</i>)<br />
fn:compare(<i>comp1,comp2,collation</i>)</td>
<td valign="top">Returns -1 if comp1 is less than comp2, 0 if comp1 is equal
to comp2, or 1 if comp1 is greater than comp2 (according to the rules of the
collation that is used)<p>Example: compare('ghi', 'ghi')<br />
Result: 0</td>
</tr>
<tr>
<td valign="top">fn:concat(<i>string,string,...</i>)</td>
<td valign="top">Returns the concatenation of the strings<p>Example: concat('XPath ','is ','FUN!')<br />
Result: 'XPath is FUN!'</td>
</tr>
<tr>
<td valign="top">fn:string-join(<i>(string,string,...),sep</i>)</td>
<td valign="top">Returns a string created by concatenating the string
arguments and using the sep argument as the separator<p>Example:
string-join(('We', 'are', 'having', 'fun!'), ' ')<br />
Result: ' We are having fun! '</p>
<p>Example: string-join(('We', 'are', 'having', 'fun!'))<br />
Result: 'Wearehavingfun!'</p>
<p>Example:string-join((), 'sep')<br />
Result: ''</td>
</tr>
<tr>
<td valign="top">fn:substring(<i>string,start,len</i>)<br />
fn:substring(<i>string,start</i>)</td>
<td valign="top">Returns the substring from the start position to the
specified length. Index of the first character is 1. If length is omitted it
returns the substring from the start position to the end<p>Example: substring('Beatles',1,4)<br />
Result: 'Beat'</p>
<p>Example: substring('Beatles',2)<br />
Result: 'eatles'</p></td>
</tr>
<tr>
<td valign="top">fn:string-length(<i>string</i>)<br />
fn:string-length()</td>
<td valign="top">Returns the length of the specified string. If there is no
string argument it returns the length of the string value of the current
node<p>Example: string-length('Beatles')<br />
Result: 7</td>
</tr>
<tr>
<td valign="top">fn:normalize-space(<i>string</i>)<br />
fn:normalize-space()</td>
<td valign="top">Removes leading and trailing spaces from the specified string, and
replaces all internal sequences of white space with one and returns the
result. If there is no string argument it does the same on the current node<p>Example: normalize-space(' The XML ')<br />
Result: 'The XML'</td>
</tr>
<tr>
<td valign="top">fn:normalize-unicode()</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">fn:upper-case(<i>string</i>)</td>
<td valign="top">Converts the string argument to upper-case<p>Example: upper-case('The XML')<br />
Result: 'THE XML'</td>
</tr>
<tr>
<td valign="top">fn:lower-case(<i>string</i>)</td>
<td valign="top">Converts the string argument to lower-case<p>Example: lower-case('The XML')<br />
Result: 'the xml'</td>
</tr>
<tr>
<td valign="top">fn:translate(<i>string1,string2,string3</i>)</td>
<td valign="top">Converts string1 by replacing the characters in string2
with the characters in string3<p>Example: translate('12:30','30','45')<br />
Result: '12:45'</p>
<p>Example: translate('12:30','03','54')<br />
Result: '12:45'</p>
<p>Example: translate('12:30','0123','abcd')<br />
Result: 'bc:da'</p></td>
</tr>
<tr>
<td valign="top">fn:escape-uri(<i>stringURI,esc-res</i>)</td>
<td valign="top">Example: escape-uri("http://example.com/test#car", true())<br />
Result: "http%3A%2F%2Fexample.com%2Ftest#car"<p>Example: escape-uri("http://example.com/test#car",
false())<br />
Result: "http://example.com/test#car"</p>
<p>Example: escape-uri ("http://example.com/~b閎
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -