XPath
<XML_XPath> Bài 8: Một số cú pháp cơ bản của XPath.
1.Select node
Các bạn có thể đọc tại http://www.w3schools.com/xsl/xpath_operators.asp.
3. Ví dụ: <nguồn https://www.w3.org>
- para
selects thepara
element children of the context node- *
selects all element children of the context node- text()
selects all text node children of the context node- @name
selects thename
attribute of the context node- @*
selects all the attributes of the context node- para[1]
selects the firstpara
child of the context node- para[fn:last()]
selects the lastpara
child of the context node- */para
selects allpara
grandchildren of the context node- /book/chapter[5]/section[2]
selects the secondsection
of the fifthchapter
of thebook
whose parent is the document node that contains the context node- chapter//para
selects thepara
element descendants of thechapter
element children of the context node- //para
selects all thepara
descendants of the root document node and thus selects allpara
elements in the same document as the context node- //@version
selects all theversion
attribute nodes that are in the same document as the context node- //list/member
selects all themember
elements in the same document as the context node that have alist
parent- .//para
selects thepara
element descendants of the context node- ..
selects the parent of the context node- ../@lang
selects thelang
attribute of the parent of the context node- para[@type="warning"]
selects allpara
children of the context node that have atype
attribute with valuewarning
- para[@type="warning"][5]
selects the fifthpara
child of the context node that has atype
attribute with valuewarning
- para[5][@type="warning"]
selects the fifthpara
child of the context node if that child has atype
attribute with valuewarning
- chapter[title="Introduction"]
selects thechapter
children of the context node that have one or moretitle
children whose typed value is equal to the stringIntroduction
- chapter[title]
selects thechapter
children of the context node that have one or moretitle
children- employee[@secretary and @assistant]
selects all theemployee
children of the context node that have both asecretary
attribute and anassistant
attribute- book/(chapter|appendix)/section
selects everysection
element that has a parent that is either achapter
or anappendix
element, that in turn is a child of abook
element that is a child of the context node.- - If
E
is any expression that returns a sequence of nodes, then the expressionE/.
returns the same nodes in document order, with duplicates eliminated based on node identity.
4. Các Hàm <Functions>
4.1 Boolean functions ( T - F )
• Boolean boolean(arg) //returns false if object equal to zero/NaN/empty
• Boolean false() //returns the Boolean value false
• Boolean lang(string arg) //to check language which is used in context node
• Boolean not(arg) //
• Boolean true() // returns the Boolean value true
4.2 Node-set Functions
• number count(node-set arg) //returns the number of nodes
• node-set id(string arg) //returns a node-set
• last() // returns a value equal to the context size
• string local-name(optional node-set arg) //returns local name(context node)
• string name(optional node-set arg) //returns the nam of node in QName format
• string namespace-uri(optional node-set arg) //returns namespace-uri of node-set
• Number position() //returns value equal to the context position
4.3 Numeric Functions
• number ceiling( number arg) //returns the smallest integer greater than this
• number floor(number arg) //returns the largest integer that is lower than this
• number number(arg) //to convert string, Boolean, node-set to number //returns NaN if can not convert
• number round(number arg) //returns the integer that is closest to the number arg
• number sum(node-set arg) // return sum of node in node-set // return NaN if node can’t converted to number
4.4 String Functions
• string concat(string arg1, arg2) //returns the concatenation of those strings
• Boolean contains(string arg1, arg2) //returns true if arg1 contains arg2
• string normalize-space(string arg1) //=trim & replace whitespace=single space
• Boolean start-with(string arg1, arg2) //returns true if arg1 starts with arg2
• string string(arg) //to convert Boolean, node-set, number to string
• number string-length(string arg) //returns the length of the string arg
• string substring(string arg1, number arg2, optional number arg3) //return substring of arg1
• string substring-before(string arg1, arg2) //
• string substring-after(string arg1, arg2) //
• string translate(string arg1, arg2, arg 3) //
Chúc các bạn thành công!
ahihi thanks
ReplyDelete