转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 电脑应用 >> 电脑技术 >> 正文
XPath Tutorial-from w3schools.com         ★★★

XPath Tutorial-from w3schools.com

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3420 更新时间: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]  下一页


[系统软件]给IE增加dom3xpath支持  [VB.NET程序]VBCOM TUTORIAL(3)
[VB.NET程序]VBCOM TUTORIAL(2)  [VB.NET程序]VBCOM TUTORIAL(1)
[VB.NET程序]Microsoft Agent Tutorial Chapter 2  [VB.NET程序]Microsoft Agent Tutorial Chapter 1
[Web开发]XSLT轻松入门第四章:XPath的语法  [Web开发]XPath 2.0 的新特性
[Web开发]JDOM/XPATH编程指南  [Web开发].NET中的xpath
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

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

    同类栏目
    · 电脑技术  · 操作系统
    · 磁盘工具  · 视音频技术
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

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

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台