转至繁体中文版     | 网站首页 | 文章中心 | 下载中心 | 图片中心 | 笑话频道 | 教程频道 | 会员中心 | 雁过留声 | 
最新公告:     "MinTao学以致用网"欢迎您的光临,你的支持便是我们的动力,欢迎广大网友和各界人士亲临指导,你们的一个小小的建议便是我们发展的开路石!  [MinTao  2007年9月5日]        
您现在的位置: MinTao学以致用网 >> 文章中心 >> 电子课堂 >> 电脑应用 >> 电脑技术 >> 文章正文
专题栏目
更多内容
最新推荐 更多内容
相关文章
没有相关文章
更多内容
XPath Tutorial-from w3schools.com           ★★★
XPath Tutorial-from w3schools.com
作者:佚名 文章来源:ofaq 点击数: 更新时间:2006-7-27
Path supports numerical, equality, relational, and Boolean expressions.


Numerical Expressions

Numerical expressions are used to perform arithmetic operations on numbers.

Operator Description Example Result + Addition 6 + 4 10 - Subtraction 6 - 4 2 * Multiplication

6 * 4

24 div Division 8 div 4 2 mod Modulus (division remainder) 5 mod 2 1

Note: XPath always converts each operand to a number before performing an arithmetic expression.


Equality Expressions

Equality expressions are used to test the equality between two values.

Operator Description Example Result = Like (equal) price=9.80 true (if price is 9.80) != Not like (not equal) price!=9.80 false

Testing Against a Node-Set

If the test value is tested for equality against a node-set, the result is true if the node-set contains any node with a value that matches the test value.

If the test value is tested for not equal against a node-set, the result is true if the node-set contains any node with a value that is different from the test value.

The result is that the node-set can be equal and not equal at the same time !!!


Relational Expressions

Relational expressions are used to compare two values.

Operator Description Example Result < Less than price<9.80 false (if price is 9.80) <= Less or equal price<=9.80 true > Greater than price>9.80 false >= Greater or equal price>=9.80 true

Note: XPath always converts each operand to a number before performing the evaluation.


Boolean Expressions

Boolean expressions are used to compare two values.

Operator Description Example Result or or price=9.80 or price=9.70 true (if price is 9.80) and and price<=9.80 and price=9.70 false

XPath Functions

Previous Next

XPath contains a function library for converting data.


XPath Function Library

The XPath function library contains a set of core functions for converting and translating data.


Node Set Functions

Name Description Syntax count() Returns the number of nodes in a node-set number=count(node-set) id() Selects elements by their unique ID node-set=id(value) last() Returns the position number of the last node in the processed node list number=last() local-name() Returns the local part of a node. A node usually consists of a prefix, a colon, followed by the local name string=local-name(node) name() Returns the name of a node string=name(node) namespace-uri() Returns the namespace URI of a specified node uri=namespace-uri(node) position() Returns the position in the node list of the node that is currently being processed number=position()

String Functions

Name Description Syntax & Example concat() Returns the concatenation of all its arguments string=concat(val1, val2, ..)

Example:
concat(''''The'''','''' '''',''''XML'''')
Result: ''''The XML''''

contains() Returns true if the second string is contained within the first string, otherwise it returns false

bool=contains(val,substr)

Example:
contains(''''XML'''',''''X'''')
Result: true

normalize-space() Removes leading and trailing spaces from a string, and replaces all internal sequences of white with one white space string=normalize-space(string)

Example:
normalize-space('''' The   XML '''')
Result: ''''The XML''''

starts-with() Returns true if the first string starts with the second string, otherwise it returns false bool=starts-with(string,substr)

Example:
starts-with(''''XML'''',''''X'''')
Result: true

string() Converts the value argument to a string string(value)

Example:
string(314)
Result: ''''314''''

string-length() Returns the number of characters in a string number=string-length(string)

Example:
string-length(''''Beatles'''')
Result: 7

substring() Returns a part of the string in the string argument string=substring(string,start,length)

Example:
substring(''''Beatles'''',1,4)
Result: ''''Beat''''

substring-after() Returns the part of the string in the string argument that occurs after the substring in the substr argument

string=substring-after(string,substr)

Example:
substring-after(''''12/10'''',''''/'''')
Result: ''''10''''

substring-before() Returns the part of the string in the string argument that occurs before the substring in the substr argument

string=substring-before(string,substr)

Example:
substring-before(''''12/10'''',''''/'''')
Result: ''''12''''

translate() Performs a character by character replacement. It looks in the value argument for characters contained in string1, and replaces each character for the one in the same position in the string2 string=translate(value,string1,string2)

Examples:
translate(''''12:30'''',''''30'''',''''45'''')
Result: ''''12:45''''

translate(''''12:30'''',''''03'''',''''54'''')
Result: ''''12:45''''

translate(''''12:30'''',''''0123'''',''''abcd'''')
Result: ''''bc:da''''

Number Functions

Name Description Syntax & Example ceiling() Returns the smallest integer that is not less than the number argument number=ceiling(number)

Example:
ceiling(3.14)
Result: 4

floor() Returns the largest integer that is not greater than the number argument

number=floor(number)

Example:
floor(3.14)
Result: 3

number() Converts the value argument to a number

number=number(value)

Example:
number(''''100'''')
Result: 100

round() Rounds the number argument to the nearest integer integer=round(number)

Example:
round(3.14)
Result: 3

sum() Returns the total value of a set of numeric values in a node-set number=sum(nodeset)

Example:
sum(/cd/price)

Boolean Functions

Name Description Syntax & Example boolean() Converts the value argument to Boolean and returns true or false bool=boolean(value) false() Returns false false()

Example:
number(false())
Result: 0

lang() Returns true if the language argument matches the language of the xsl:lang element, otherwise it returns false bool=lang(language) not() Returns true if the condition argument is false, and false if the condition argument is true bool=not(condition)

Example:
not(false())

true() Returns true true()

Example:
number(true())
Result: 1



XPath Examples

Previous Next

We will use the CD catalog from our XML tutorial to demonstrate some XPath examples.


The CD catalog

If you have studied our XML tutorial, you will remember this XML document:

(A fraction of the CD catalog)

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
  <cd>
    &l

上一页  [1] [2] [3] [4] 下一页

文章录入:mintao    责任编辑:mintao 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007 MinTao学以致用网(www.mintao.net) Inc All Rights Reserved.
    QQ:543098146有事请Q我! QQ:261561092有事请Q我 QQ:179647303有事请Q我 MSN:min906@126.com
    站长:MinTao 信息产业部ICP备案号:鄂ICP备07500065号

    学以致用是我们学习者的至高境界和不懈追求,[MinTao学以致用网]与大家共同学习,共同进步……
    信息产业部备案
    *鄂ICP备07500065号