{"id":106,"date":"2018-07-26T08:45:31","date_gmt":"2018-07-26T08:45:31","guid":{"rendered":"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=106"},"modified":"2018-08-02T06:13:38","modified_gmt":"2018-08-02T06:13:38","slug":"xpath","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/chapter\/xpath\/","title":{"rendered":"XPath"},"content":{"raw":"<strong>Introduction<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">XPath (the XML Path language) is a language for finding information in an XML document. It is a major element in the XSLT standard. Without XPath knowledge you will not be able to create XSLT documents. XPath uses path expressions to navigate in XML documents and to select nodes or node-sets in an XML document. These path expressions look very much like the expressions used in JavaScript, Java, XML Schema, PHP, Python, C and C++, and lots of other languages.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">XPath is a syntax for defining parts of an XML document. It contains a library of standard functions. It is also used in XQuery, XPointer and XLink.<\/p>\r\n<p style=\"text-align: justify\">Figure 14.1 shows how XPath, the path language is useful for other XML technologies like XSLT, XQuery, XPointer and XLink.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-109 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-47.png\" alt=\"\" width=\"465\" height=\"289\" \/><\/p>\r\n\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>XPath Nodes<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">XPath identifies seven kinds of nodes like Element node, Attribute node, Text node, Namespace node,Processing Instruction node, Comment node and Document node. XML documents are also treated as trees of nodes.<\/p>\r\n&nbsp;\r\n\r\n<strong>XML CODE<\/strong>\r\n\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;bookstore&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;book&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">ROOT ELEMENT NODE<\/em><span style=\"text-align: initial;font-size: 1em\">)<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;title lang=\"en\"&gt;Harry Potter&lt;\/title&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;<\/span><span style=\"text-align: initial;font-size: 1em\">author&gt;J K. Rowling&lt;\/author&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;year&gt;2005&lt;\/year&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;price&gt;29.99&lt;\/price&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/book&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/bookstore&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">ATTRIBUTE NODE<\/em><span style=\"text-align: initial;font-size: 1em\">)<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">ELEMENT NODE)<\/em>\r\n\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">Relationship of Nodes<\/strong>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 PARENT NODE<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Each element and attribute has <em>one parent<\/em>. In the above example the &lt;book&gt; element is the parent of the &lt;title&gt;, &lt;author&gt;, &lt;year&gt;, and &lt;price&gt;.<\/p>\r\n&nbsp;\r\n\r\n<strong>CHILDREN NODE<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Element nodes may <em>have zero, one or more children<\/em>. The &lt;title&gt;, &lt;author&gt;, &lt;year&gt;, and &lt;price&gt; elements are all children of the &lt;book&gt; element.<\/p>\r\n&nbsp;\r\n\r\n<strong>SIBLING NODE<\/strong>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\">\u00a0 Nodes that <em>have the same parent<\/em>. The &lt;title&gt;, &lt;author&gt;, &lt;year&gt;, and &lt;price&gt; elements are all siblings <strong>ANCESTOR NODE<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">A node's parent, parent's parent, etc. The ancestors of the &lt;title&gt; element are the &lt;book&gt; element and the &lt;bookstore&gt; element.<\/p>\r\n&nbsp;\r\n\r\n<strong>DESCENDANT NODE<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A node's children, children's children, etc. In the above example, descendants of the &lt;bookstore&gt; element are the &lt;book&gt;, &lt;title&gt;, &lt;author&gt;, &lt;year&gt;, and &lt;price&gt; elements.<\/p>\r\n&nbsp;\r\n\r\n<strong>XPath Syntax<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-111 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-48.png\" alt=\"\" width=\"655\" height=\"366\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>XPath Syntax for Path Expression<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">XPath uses a path expression to select node or list of nodes from an XML document.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-112 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-49.png\" alt=\"\" width=\"522\" height=\"451\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>XPath Syntax for Predicates<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Predicate refers to XPath expression written in square brackets. Predicates are used to find a specific node or a node that contains a specific value. Table 14.3 shows how to give path expressions with predicates.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-113 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-50.png\" alt=\"\" width=\"593\" height=\"377\" \/><\/p>\r\n&nbsp;\r\n\r\nTable 14.4 shows how to give path expressions with predicates along with attributes.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-114 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-51.png\" alt=\"\" width=\"579\" height=\"395\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Wildcard in XPath<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Selecting Unknown Nodes<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">XPath wildcards can be used to select unknown XML nodes. XPath defines following wildcards on nodes to be used with XPath expressions. Table 14.5 shows the different wildcards used and its description.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-115 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-52.png\" alt=\"\" width=\"538\" height=\"256\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Selecting Several Paths<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">By using the <strong>'|'<\/strong> operator in an XPath expression you can select several paths. In the Table 14.6 below we have listed some path expressions that can be given with several paths and the result of the expressions.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-116 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-53.png\" alt=\"\" width=\"566\" height=\"289\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>XPath Axes<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Axes are named so because they refers to axis on which elements are lying relative to an e lement.Following is the list of various Axes values given in Table 14.6 and Table 14.7.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-117 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-54.png\" alt=\"\" width=\"528\" height=\"407\" \/><\/p>\r\n&nbsp;\r\n\r\nAn axis defines a node-set relative to the current node\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-118 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-55.png\" alt=\"\" width=\"547\" height=\"345\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Location Path Expression<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A location path can be absolute or relative. An absolute location path starts with a slash ( \/ ) and a relative location path does not. In both cases the location path consists of one or more steps, each separated by a slash:<\/p>\r\n&nbsp;\r\n\r\nAn absolute location path will be given as: \/step\/step\/...\r\n\r\nA relative location path will be given as:\u00a0\u00a0\u00a0\u00a0\u00a0 step\/step\/...\r\n\r\nEach step is evaluated against the nodes in the current node-set.\r\n\r\n&nbsp;\r\n\r\n<strong>Location Path Expression Steps &amp; Syntax<\/strong>\r\n\r\n&nbsp;\r\n\r\nLocation path expression consists of following steps:\r\n<ol>\r\n \t<li>An axis that defines the tree-relationship between the selected nodes and the current node.<\/li>\r\n \t<li>A node-test that identifies a node within an axis or specifies the name of the node to be selected.<\/li>\r\n \t<li>Zero or more predicates to further refine the selected node-set.<\/li>\r\n<\/ol>\r\nThe syntax for a location step is:\r\n\r\naxisname::nodetest[predicate]\r\n\r\n&nbsp;\r\n\r\n<strong>Location Path Expression Examples<\/strong>\r\n\r\n&nbsp;\r\n\r\nAn XPath expression returns either a node-set, a string, a Boolean, or a number.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-119 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-56.png\" alt=\"\" width=\"590\" height=\"610\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>XPath Operators<\/strong>\r\n\r\n&nbsp;\r\n\r\nTable 14.8 shows a list of the operators that can be used in XPath expressions.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-120 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-57.png\" alt=\"\" width=\"589\" height=\"481\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0XPath Expressions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">XPath query string to retrieve information from XML documents is called expression. XPath expressions are classified as,<\/p>\r\n\r\n<ul>\r\n \t<li>Sequence Expressions<\/li>\r\n \t<li>Range Expressions<\/li>\r\n \t<li>Filter Expressions<\/li>\r\n \t<li>Arithmetic Expression<\/li>\r\n \t<li>Comparison Expression<\/li>\r\n \t<li>Logical Expression<\/li>\r\n \t<li>For Expression<\/li>\r\n \t<li>Conditional Expression<\/li>\r\n \t<li>Quantified Expression<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 XPath Functions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The XPath language provides a core library of functions that deal with Node set functions for working with node-sets, either the implicit current node set or one passed as a parameter.String functions are provided for working with strings and include type coercions.Boolean functions are provided for working with Booleans, including type coercions.Number functions are provided for working with numbers, including type coercions.<\/p>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 XPath Function Example<\/strong><\/p>\r\n\r\n<div style=\"text-align: justify\">\r\n\r\n&nbsp;\r\n\r\nSome examples using XPath functions are:\r\n\r\nTo determine the number of articles written by Mr. Jones:\r\n\r\ncount(\/journal\/article[author\/last=\"Jones\"])\r\n\r\nTo find all authors whose last name begins with Mc:\r\n\r\n\/journal\/article[starts-with(author\/last,\"Mc\")]\r\n\r\n&nbsp;\r\n\r\n<strong>\u00a0XPath Node Set Function<\/strong>\r\n\r\n&nbsp;\r\n\r\nBelow is the list of some of the XPath Node set functions.\r\n\r\n&nbsp;\r\n\r\n<strong>number last() <\/strong>- Returns the index of the last item of the current node set.\r\n\r\nExample - \/journal\/article[last()]\r\n\r\n<strong>number position() - <\/strong>Returns the index of the current item in the current node set.\r\n\r\nExample - \/journal\/article[position()&lt;3]\r\n\r\n<strong>number count(node-set) - <\/strong>Returns the number of items in the argument node set.\r\n\r\nExample - count(\/journal\/article)\r\n\r\n<strong>node-set id(object) - <\/strong>Returns the elements with the ID specified.\r\n\r\nExample - id(\"article.1\")\/author\/last\r\n\r\n&nbsp;\r\n\r\n<strong>XPath String Function<\/strong>\r\n\r\n&nbsp;\r\n\r\nBelow is the list of some of the XPath string functions.\r\n\r\n<strong>string string(object?) <\/strong>- Converts an object (possibly the current context node) to its string value. Example - \/journal\/article\/author[string()='Jones']\r\n\r\n<strong>string concat(string, string, string*) <\/strong>- Concatenates two or more strings together.\r\n\r\nExample - concat(author\/salutation, ' ', author\/last)\r\n\r\n<strong>string starts-with(string, string) <\/strong>- Determines if the first argument starts with the second\u00a0argument string.\r\n\r\nExample - \/journal\/article[starts-with(title, 'Advanced')]\r\n\r\n<strong>string ends-with(string, string) <\/strong>- Determines if the first argument ends with the second argument string.\r\n\r\nExample - \/journal\/article[ends-with(title, 'Advanced')]\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">string contains(string, string) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Determines if the first argument contains the second argument string.<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">Example - \/journal\/article[contains(title, 'XPath')]<\/span>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">string substring-before(string, string) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Retrieves the substring of the first argument that occurs before the first occurrence of the second argument string.<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">Example - substring-before(\/journal\/article[1]\/date, '\/')<\/span>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">string substring-after(string, string) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Retrieves the substring of the first argument that occurs after the first occurrence of the second argument string.<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">Example - substring-after(\/journal\/article[1]\/date, '\/')<\/span>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">string substring(string, number, number?) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Retrieves the substring of the first argument starting at the index of the second number argument, for the length of the optional third argument.<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">Example - substring('Jones', 3)<\/span>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">number string-length(string?) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Determines the length of a string, or the current context node\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">coerced to a string.<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">Example - \/journal\/article[string-length(author\/last) &gt; 9]<\/span>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">string normalize-space(string?) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Retrieves the string argument or context node with all space normalized, trimming white space from the ends and compressing consecutive white space elements to a single space.<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">Example - normalize-space(\/journal\/article[1]\/content)<\/span>\r\n\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">XPath Boolean Function<\/strong>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0Below is the list of some of the XPath Boolean functions.<\/p>\r\n<p style=\"text-align: justify\"><strong>Boolean boolean(object) - <\/strong>Converts the argument to a Boolean value.<\/p>\r\n<p style=\"text-align: justify\">Example - boolean(\/journal\/article\/author\/last[.='Jones'])<\/p>\r\n<p style=\"text-align: justify\"><strong>Boolean not(boolean) - <\/strong>Negates the boolean value.<\/p>\r\n<p style=\"text-align: justify\">Example - not(\/journal\/article\/author\/last[.='Jones'])<\/p>\r\n<p style=\"text-align: justify\"><strong>Boolean boolean-from-string(string) - <\/strong>Returns true if the required parameter string is true, 1, or<\/p>\r\n<p style=\"text-align: justify\">Yes. In all other conditions, false is returned.<\/p>\r\n<p style=\"text-align: justify\">Example - boolean-from-string(..\/pay_entire_amount)<\/p>\r\n<p style=\"text-align: justify\"><strong>Boolean true() - <\/strong>The Boolean value is true.<\/p>\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">Boolean false() - <\/strong><span style=\"text-align: initial;font-size: 1em\">The Boolean value is false.<\/span><\/p>\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">object if(boolean,object,object) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Evaluates the first parameter as a Boolean, returning the second parameter when true, otherwise the third parameter.<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example \u2013 if(\/journal\/article\/author\/last[.='Jones'],'Match found','No match')<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">XPath Number Function<\/strong><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Below is the list of some of the XPath Number functions.<\/span><\/p>\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">number number(object?) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Converts the argument or context node to a number value.<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example - \/journal[number(year)=2003]<\/span><\/p>\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">number sum(node-set) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Sums the node set value.<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example - sum(\/journal\/article\/author\/age)<\/span><\/p>\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">number floor(number) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Returns the largest integer that is not greater than the number\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">argument.<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example - floor(100.5)=100<\/span><\/p>\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">number round(number) - <\/strong><span style=\"text-align: initial;font-size: 1em\">Rounds the number argument.<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example - ceiling(100.3)=100<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">Summary<\/strong><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This module explains about XPath and how to define XPath expressions to navigate in XML documents. It also explores about XPath syntax, Location path expression ,Absolute\/Relative path, Predicate, Wildcard, Axes and XPath operators and functions.<\/p>\r\n\r\n<\/div>\r\n&nbsp;","rendered":"<p><strong>Introduction<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">XPath (the XML Path language) is a language for finding information in an XML document. It is a major element in the XSLT standard. Without XPath knowledge you will not be able to create XSLT documents. XPath uses path expressions to navigate in XML documents and to select nodes or node-sets in an XML document. These path expressions look very much like the expressions used in JavaScript, Java, XML Schema, PHP, Python, C and C++, and lots of other languages.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">XPath is a syntax for defining parts of an XML document. It contains a library of standard functions. It is also used in XQuery, XPointer and XLink.<\/p>\n<p style=\"text-align: justify\">Figure 14.1 shows how XPath, the path language is useful for other XML technologies like XSLT, XQuery, XPointer and XLink.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-109 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-47.png\" alt=\"\" width=\"465\" height=\"289\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-47.png 465w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-47-300x186.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-47-65x40.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-47-225x140.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-47-350x218.png 350w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>XPath Nodes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">XPath identifies seven kinds of nodes like Element node, Attribute node, Text node, Namespace node,Processing Instruction node, Comment node and Document node. XML documents are also treated as trees of nodes.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>XML CODE<\/strong><\/p>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;bookstore&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;book&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">ROOT ELEMENT NODE<\/em><span style=\"text-align: initial;font-size: 1em\">)<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;title lang=&#8221;en&#8221;&gt;Harry Potter&lt;\/title&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;<\/span><span style=\"text-align: initial;font-size: 1em\">author&gt;J K. Rowling&lt;\/author&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;year&gt;2005&lt;\/year&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;price&gt;29.99&lt;\/price&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/book&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/bookstore&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">ATTRIBUTE NODE<\/em><span style=\"text-align: initial;font-size: 1em\">)<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">ELEMENT NODE)<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">Relationship of Nodes<\/strong><\/p>\n<div>\n<p><strong>\u00a0 \u00a0 PARENT NODE<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Each element and attribute has <em>one parent<\/em>. In the above example the &lt;book&gt; element is the parent of the &lt;title&gt;, &lt;author&gt;, &lt;year&gt;, and &lt;price&gt;.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>CHILDREN NODE<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Element nodes may <em>have zero, one or more children<\/em>. The &lt;title&gt;, &lt;author&gt;, &lt;year&gt;, and &lt;price&gt; elements are all children of the &lt;book&gt; element.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>SIBLING NODE<\/strong><\/p>\n<\/div>\n<p style=\"text-align: justify\">\u00a0 Nodes that <em>have the same parent<\/em>. The &lt;title&gt;, &lt;author&gt;, &lt;year&gt;, and &lt;price&gt; elements are all siblings <strong>ANCESTOR NODE<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A node&#8217;s parent, parent&#8217;s parent, etc. The ancestors of the &lt;title&gt; element are the &lt;book&gt; element and the &lt;bookstore&gt; element.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>DESCENDANT NODE<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A node&#8217;s children, children&#8217;s children, etc. In the above example, descendants of the &lt;bookstore&gt; element are the &lt;book&gt;, &lt;title&gt;, &lt;author&gt;, &lt;year&gt;, and &lt;price&gt; elements.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>XPath Syntax<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-111 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-48.png\" alt=\"\" width=\"655\" height=\"366\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-48.png 655w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-48-300x168.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-48-65x36.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-48-225x126.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-48-350x196.png 350w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>XPath Syntax for Path Expression<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">XPath uses a path expression to select node or list of nodes from an XML document.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-112 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-49.png\" alt=\"\" width=\"522\" height=\"451\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-49.png 522w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-49-300x259.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-49-65x56.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-49-225x194.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-49-350x302.png 350w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>XPath Syntax for Predicates<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Predicate refers to XPath expression written in square brackets. Predicates are used to find a specific node or a node that contains a specific value. Table 14.3 shows how to give path expressions with predicates.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-113 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-50.png\" alt=\"\" width=\"593\" height=\"377\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-50.png 593w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-50-300x191.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-50-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-50-225x143.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-50-350x223.png 350w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Table 14.4 shows how to give path expressions with predicates along with attributes.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-114 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-51.png\" alt=\"\" width=\"579\" height=\"395\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-51.png 579w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-51-300x205.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-51-65x44.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-51-225x153.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-51-350x239.png 350w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Wildcard in XPath<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Selecting Unknown Nodes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">XPath wildcards can be used to select unknown XML nodes. XPath defines following wildcards on nodes to be used with XPath expressions. Table 14.5 shows the different wildcards used and its description.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-115 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-52.png\" alt=\"\" width=\"538\" height=\"256\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-52.png 538w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-52-300x143.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-52-65x31.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-52-225x107.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-52-350x167.png 350w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Selecting Several Paths<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">By using the <strong>&#8216;|&#8217;<\/strong> operator in an XPath expression you can select several paths. In the Table 14.6 below we have listed some path expressions that can be given with several paths and the result of the expressions.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-116 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-53.png\" alt=\"\" width=\"566\" height=\"289\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-53.png 566w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-53-300x153.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-53-65x33.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-53-225x115.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-53-350x179.png 350w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>XPath Axes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Axes are named so because they refers to axis on which elements are lying relative to an e lement.Following is the list of various Axes values given in Table 14.6 and Table 14.7.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-117 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-54.png\" alt=\"\" width=\"528\" height=\"407\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-54.png 528w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-54-300x231.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-54-65x50.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-54-225x173.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-54-350x270.png 350w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>An axis defines a node-set relative to the current node<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-118 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-55.png\" alt=\"\" width=\"547\" height=\"345\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-55.png 547w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-55-300x189.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-55-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-55-225x142.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-55-350x221.png 350w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Location Path Expression<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A location path can be absolute or relative. An absolute location path starts with a slash ( \/ ) and a relative location path does not. In both cases the location path consists of one or more steps, each separated by a slash:<\/p>\n<p>&nbsp;<\/p>\n<p>An absolute location path will be given as: \/step\/step\/&#8230;<\/p>\n<p>A relative location path will be given as:\u00a0\u00a0\u00a0\u00a0\u00a0 step\/step\/&#8230;<\/p>\n<p>Each step is evaluated against the nodes in the current node-set.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Location Path Expression Steps &amp; Syntax<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Location path expression consists of following steps:<\/p>\n<ol>\n<li>An axis that defines the tree-relationship between the selected nodes and the current node.<\/li>\n<li>A node-test that identifies a node within an axis or specifies the name of the node to be selected.<\/li>\n<li>Zero or more predicates to further refine the selected node-set.<\/li>\n<\/ol>\n<p>The syntax for a location step is:<\/p>\n<p>axisname::nodetest[predicate]<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Location Path Expression Examples<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>An XPath expression returns either a node-set, a string, a Boolean, or a number.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-119 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-56.png\" alt=\"\" width=\"590\" height=\"610\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-56.png 590w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-56-290x300.png 290w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-56-65x67.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-56-225x233.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-56-350x362.png 350w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>XPath Operators<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Table 14.8 shows a list of the operators that can be used in XPath expressions.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-120 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-57.png\" alt=\"\" width=\"589\" height=\"481\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-57.png 589w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-57-300x245.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-57-65x53.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-57-225x184.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-57-350x286.png 350w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0XPath Expressions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">XPath query string to retrieve information from XML documents is called expression. XPath expressions are classified as,<\/p>\n<ul>\n<li>Sequence Expressions<\/li>\n<li>Range Expressions<\/li>\n<li>Filter Expressions<\/li>\n<li>Arithmetic Expression<\/li>\n<li>Comparison Expression<\/li>\n<li>Logical Expression<\/li>\n<li>For Expression<\/li>\n<li>Conditional Expression<\/li>\n<li>Quantified Expression<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 XPath Functions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The XPath language provides a core library of functions that deal with Node set functions for working with node-sets, either the implicit current node set or one passed as a parameter.String functions are provided for working with strings and include type coercions.Boolean functions are provided for working with Booleans, including type coercions.Number functions are provided for working with numbers, including type coercions.<\/p>\n<\/div>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 XPath Function Example<\/strong><\/p>\n<div style=\"text-align: justify\">\n<p>&nbsp;<\/p>\n<p>Some examples using XPath functions are:<\/p>\n<p>To determine the number of articles written by Mr. Jones:<\/p>\n<p>count(\/journal\/article[author\/last=&#8221;Jones&#8221;])<\/p>\n<p>To find all authors whose last name begins with Mc:<\/p>\n<p>\/journal\/article[starts-with(author\/last,&#8221;Mc&#8221;)]<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u00a0XPath Node Set Function<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Below is the list of some of the XPath Node set functions.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>number last() <\/strong>&#8211; Returns the index of the last item of the current node set.<\/p>\n<p>Example &#8211; \/journal\/article[last()]<\/p>\n<p><strong>number position() &#8211; <\/strong>Returns the index of the current item in the current node set.<\/p>\n<p>Example &#8211; \/journal\/article[position()&lt;3]<\/p>\n<p><strong>number count(node-set) &#8211; <\/strong>Returns the number of items in the argument node set.<\/p>\n<p>Example &#8211; count(\/journal\/article)<\/p>\n<p><strong>node-set id(object) &#8211; <\/strong>Returns the elements with the ID specified.<\/p>\n<p>Example &#8211; id(&#8220;article.1&#8221;)\/author\/last<\/p>\n<p>&nbsp;<\/p>\n<p><strong>XPath String Function<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Below is the list of some of the XPath string functions.<\/p>\n<p><strong>string string(object?) <\/strong>&#8211; Converts an object (possibly the current context node) to its string value. Example &#8211; \/journal\/article\/author[string()=&#8217;Jones&#8217;]<\/p>\n<p><strong>string concat(string, string, string*) <\/strong>&#8211; Concatenates two or more strings together.<\/p>\n<p>Example &#8211; concat(author\/salutation, &#8216; &#8216;, author\/last)<\/p>\n<p><strong>string starts-with(string, string) <\/strong>&#8211; Determines if the first argument starts with the second\u00a0argument string.<\/p>\n<p>Example &#8211; \/journal\/article[starts-with(title, &#8216;Advanced&#8217;)]<\/p>\n<p><strong>string ends-with(string, string) <\/strong>&#8211; Determines if the first argument ends with the second argument string.<\/p>\n<p>Example &#8211; \/journal\/article[ends-with(title, &#8216;Advanced&#8217;)]<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">string contains(string, string) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Determines if the first argument contains the second argument string.<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">Example &#8211; \/journal\/article[contains(title, &#8216;XPath&#8217;)]<\/span><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">string substring-before(string, string) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Retrieves the substring of the first argument that occurs before the first occurrence of the second argument string.<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">Example &#8211; substring-before(\/journal\/article[1]\/date, &#8216;\/&#8217;)<\/span><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">string substring-after(string, string) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Retrieves the substring of the first argument that occurs after the first occurrence of the second argument string.<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">Example &#8211; substring-after(\/journal\/article[1]\/date, &#8216;\/&#8217;)<\/span><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">string substring(string, number, number?) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Retrieves the substring of the first argument starting at the index of the second number argument, for the length of the optional third argument.<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">Example &#8211; substring(&#8216;Jones&#8217;, 3)<\/span><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">number string-length(string?) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Determines the length of a string, or the current context node\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">coerced to a string.<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">Example &#8211; \/journal\/article[string-length(author\/last) &gt; 9]<\/span><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">string normalize-space(string?) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Retrieves the string argument or context node with all space normalized, trimming white space from the ends and compressing consecutive white space elements to a single space.<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">Example &#8211; normalize-space(\/journal\/article[1]\/content)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">XPath Boolean Function<\/strong><\/p>\n<\/div>\n<div>\n<p style=\"text-align: justify\">\u00a0 \u00a0Below is the list of some of the XPath Boolean functions.<\/p>\n<p style=\"text-align: justify\"><strong>Boolean boolean(object) &#8211; <\/strong>Converts the argument to a Boolean value.<\/p>\n<p style=\"text-align: justify\">Example &#8211; boolean(\/journal\/article\/author\/last[.=&#8217;Jones&#8217;])<\/p>\n<p style=\"text-align: justify\"><strong>Boolean not(boolean) &#8211; <\/strong>Negates the boolean value.<\/p>\n<p style=\"text-align: justify\">Example &#8211; not(\/journal\/article\/author\/last[.=&#8217;Jones&#8217;])<\/p>\n<p style=\"text-align: justify\"><strong>Boolean boolean-from-string(string) &#8211; <\/strong>Returns true if the required parameter string is true, 1, or<\/p>\n<p style=\"text-align: justify\">Yes. In all other conditions, false is returned.<\/p>\n<p style=\"text-align: justify\">Example &#8211; boolean-from-string(..\/pay_entire_amount)<\/p>\n<p style=\"text-align: justify\"><strong>Boolean true() &#8211; <\/strong>The Boolean value is true.<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">Boolean false() &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">The Boolean value is false.<\/span><\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">object if(boolean,object,object) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Evaluates the first parameter as a Boolean, returning the second parameter when true, otherwise the third parameter.<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example \u2013 if(\/journal\/article\/author\/last[.=&#8217;Jones&#8217;],&#8217;Match found&#8217;,&#8217;No match&#8217;)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">XPath Number Function<\/strong><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Below is the list of some of the XPath Number functions.<\/span><\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">number number(object?) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Converts the argument or context node to a number value.<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example &#8211; \/journal[number(year)=2003]<\/span><\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">number sum(node-set) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Sums the node set value.<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example &#8211; sum(\/journal\/article\/author\/age)<\/span><\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">number floor(number) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Returns the largest integer that is not greater than the number\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">argument.<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example &#8211; floor(100.5)=100<\/span><\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">number round(number) &#8211; <\/strong><span style=\"text-align: initial;font-size: 1em\">Rounds the number argument.<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Example &#8211; ceiling(100.3)=100<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">Summary<\/strong><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This module explains about XPath and how to define XPath expressions to navigate in XML documents. It also explores about XPath syntax, Location path expression ,Absolute\/Relative path, Predicate, Wildcard, Axes and XPath operators and functions.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"author":4,"menu_order":14,"template":"","meta":{"_acf_changed":false,"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-m-vijayalakshmi"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-106","chapter","type-chapter","status-publish","hentry","contributor-dr-m-vijayalakshmi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":6,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/106\/revisions"}],"predecessor-version":[{"id":541,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/106\/revisions\/541"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/106\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapter-type?post=106"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/contributor?post=106"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/license?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}