XPath Functions Quick Reference

详细实例参考:http://www.stylusstudio.com/docs/v62/d_xpath15.html

 

Function
Source
Returns
XPath
               

            
Boolean value that is the result of converting an object to a Boolean value. See Converting an Object to Boolean.
XPath
               

            
Number that is the smallest integer that is not less than a number you specify. See Obtaining the Largest, Smallest, or Closest Number.
XPath
               

            
XPath
               

            
String that concatenates two or more strings you specify. See Concatenating Strings.
XPath
               

            
Nodes that contain the specified string. See Searching for Strings.
XPath
               

            
Number of nodes in the node-set argument. See Determining the Number of Nodes in a Collection.
XPath
               

            
Node for which the current template started its operation. See Obtaining the Current Node for the Current XSLT Template.
XSLT
               

            
Root node of the specified document. See Accessing Other Documents During Query Execution.
XSLT
               

            
Boolean value that indicates whether the specified element is supported by the XSLT processor. See Determining If Functions Are Available.
XPath
               

            
XPath
               

            
Number that is the largest integer that is not greater than a number you specify. See Obtaining the Largest, Smallest, or Closest Number.
XSLT
               

            
Boolean value that indicates whether the specified function is supported by the XPath processor. See Determining If Functions Are Available.
XSLT
               

            
String that uniquely, temporarily, identifies a node. See Generating Temporary IDs for Nodes.
XPath
               

            
Element whose id attribute value matches the specified value. See Finding an Element with a Particular ID.
XSLT
               

            
Node whose key value matches the specified key. See Finding an Element with a Particular Key.
XPath
               

            
Boolean value that indicates whether the language of the node is the language you expect. See Determining the Context Node Language.
XPath
               

            
Number of nodes in the context list. See Determining the Number of Nodes in a Collection.
XPath
               

            
Local portion of the node name, excluding the prefix. See Obtaining Namespace Information.
XPath
               

            
String that contains the tag name of the node, including namespace information, if any. See Obtaining Namespace Information.
XPath
               

            
URI for the namespace of the node. See Obtaining Namespace Information.
XPath
               

            
XPath
               

            
String without leading or trailing white space. See Normalizing Strings.
XPath
               

            
Boolean value that indicates the opposite of the specified Boolean value. See Obtaining Boolean Values.
XPath
               

            
Number that is the result of converting the specified argument to a number. See Converting an Object to a Number.
XPath
               

            
Position number of the node relative to the context node set. See Finding a Particular Node.
XPath
               

            
Processing instruction nodes. If you specify a literal argument, this function returns a processing instruction if its name matches the literal you specify. See Obtaining Particular Types of Nodes By Using Node Tests.
XPath
               

            
Number that is the closest to the argument and is an integer. See Obtaining the Largest, Smallest, or Closest Number.
XPath
               

            
Boolean value that indicates if a string starts with a particular string. See Finding Strings That Start with a Particular String.
XPath
               

            
String that is the result of converting some object to a string. See Converting Objects to Strings.
XPath
               

            
Number of characters in a string you specify. See Determining the Number of Characters in a String.
XPath
               

            
Substring that is in a particular position within its string. See Finding Substrings by Position.
XPath
               

            
Substring that appears before a string you specify. See Finding Substrings That Appear Before Strings You Specify.
XPath
               

            
Substring that appears after a string you specify. See Finding Substrings That Appear After Strings You Specify.
XPath
               

            
Number that is the sum of the values of the nodes in the specified set. See Obtaining the Sum of the Values in a Node Set.
XSLT
               

            
Object that represents the specified property. See Obtaining System Properties.
XPath
               

            
String with some characters replaced by other characters. See Replacing Characters in Strings with Characters You Specify.
XPath
               

            
XSLT
               

            
URI of an unparsed entity with the specified name. See Obtaining the URI for an Unparsed Entity.
XPath Function Quick Reference

 

XPath Syntax Quick Reference

This topic provides a quick reference for XPath expression syntax.

Axes

XPath provides the following axes:

    • ancestor
    • ancestor-or-self
    • attribute
    • child
    • descendant
    • descendant-or-self
    • following
    • following-sibling
    • namespace
    • parent
    • preceding
    • preceding-sibling
    • self

Node Tests

XPath provides the following node tests:

    • * selects all nodes of the specified name. For the attribute axis, attributes are selected. For the namespace axis, namespace nodes are selected. For all other axes, element nodes are selected.
    • comment() selects all comment nodes.
    • element_name selects all element_name nodes.
    • node() selects all nodes.
    • processing-instruction(["some_literal "]) selects all processing instructions. If some_literal is specified, processing-instruction() selects all processing instructions with some_literal as their name.
    • text() selects all text nodes.

Filters

A filter specifies a constraint on a node set with respect to an axis to produce a new node set.

Location Steps

A location step has the following format:

AxisSpecifier
              ::NodeTest
              [Filter
              ][Filter
              ]...
               

            
  

 

XPath Expression

An XPath expression has one of the following formats:

LocationStep[/LocationStep]...
               
FunctionCall()[Filter]/LocationStep[/LocationStep]...
               
(Expression)[Filter]/LocationStep[/LocationStep]...
               

            
  

 

A function call or an XPath expression in parentheses can appear only at the very beginning of an XPath expression. An expression in parentheses always returns a node set. Any function that appears at the beginning of an XPath location step expression must return a node set.

XPath Abbreviations Quick Reference

Table 68 defines the abbreviations you can use in XPath expressions:

 

Abbreviation
Description
No axis is specified in a location step.

The child axis is assumed. For example, the following two XPath expressions both return the para children of chapter children of the context node:

chapter/para
               
child::chapter/child::para
               

            
@

The attribute axis. For example, the following two XPath expressions both return para children of the context node that have type attributes with a value of warning:

para[@type="warning"]
               
child::para[attribute::type="warning"]
               

            
//
The descendant-or-self axis. For example, the following two XPath expressions both return all para descendants of the context node:
//para
               
/descendant-or-self::node()/child::para
               

            
However, it is important to note that the following two expressions are not equivalent:
/descendant::para[1]
               
//para[1]
               

            
The first expression selects the first para element that is a descendant of the context node. The second expression selects each para descendant that is the first para child of its parent.
.
A single dot is the abbreviation for self::node(). This selects the context node. For example, the following two XPath expressions both return all para descendants of the context node:
.//para
               
self::node()/descendant-or-self::node()/child::para
               

            
..
A double dot is the abbreviation for parent::node(). This selects the parent of the context node. For example, the following two XPath expressions both return the title children of the parent of the context node:
../title
               
parent::node()/child::title
               

            
Table 68. XPath Abbreviations Quick Reference

 

Table 69 shows examples of abbreviations in XPath expressions

 

Example
Description
para
Selects the para children of the context node
*
Selects all element children of the context node
node_test
Evaluates all children of the context node and returns those that test true for the particular node_test
*/para
Selects all para grandchildren of the context node
para[1]
Selects the first para child of the context node
para[last()]
Selects the last para child of the context node
/doc/chapter[5]/section[2]
Selects the second section of the fifth chapter of the doc child of the context node
para[@type="warning"]
Selects para children of the context node that have type attributes with a value of warning
para[@type="warning"][5]
Selects the fifth para child of the context node that has a type attribute with a value of warning
para[5][@type="warning"]
Selects the fifth para child of the context node if that child has a type attribute with a value of warning
chapter[title]
Selects the chapter children of the context node that have one or more title children
//para
Selects all para descendants of the document root
chapter//para
Selects all para descendants of chapter children of the context node
//olist/item
Selects all item elements that have olist parents
.
Selects the context node
.//para
Selects the para descendants of the context node
..
Selects the parent of the context node
@*
Selects all attributes of the context node
@name
Selects the name attribute of the context node
../@name
Selects the name attribute of the parent of the context node
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值