{"id":4848,"date":"2021-05-28T19:03:38","date_gmt":"2021-05-28T19:03:38","guid":{"rendered":"https:\/\/www.s-sols.com\/?post_type=doc&#038;p=4848"},"modified":"2023-05-17T15:55:22","modified_gmt":"2023-05-17T15:55:22","slug":"xpath-elements-selector-accel","status":"publish","type":"doc","link":"https:\/\/www.s-sols.com\/docs\/wordpress\/accelerator\/settings-accel\/xpath-elements-selector-accel","title":{"rendered":"XPath elements selector Accelerator for WordPress"},"content":{"rendered":"<p style=\"text-align:justify\">\n  An XPath selector is a powerful language to choose the specified set from the tags tree.\n<\/p>\n<p style=\"text-align:justify\">\n  While developing this product we wanted to use CSS selectors that simpler and more often use. But CSS doesn\u2019t allow to choose the item by index. Therefore, we decided to use XPath.\n<\/p>\n<p style=\"text-align:justify\">\n  E.g. we want to get all <code>div<\/code> tags that contain <code>comments-area<\/code> in their <code>class<\/code> attribute and have <code>id<\/code> that equals to <code>comments<\/code>. So, the result selector will be:\n<\/p>\n<p><code class=\"p\">.\/\/div[@id='comments' and contains(concat(' ',normalize-space(@class),' '),' comments-area ')]<\/code>\n<\/p>\n<p><a id=\"reqs\"><\/a>To get only first element from that set we should type:\n<\/p>\n<p><code class=\"p\">(.\/\/div[@id='comments' and contains(concat(' ',normalize-space(@class),' '),' comments-area ')])[0]<\/code>\n<\/p>\n<p>\n  To get only last element from that set we should type:\n<\/p>\n<p><code class=\"p\">(.\/\/div[@id='comments' and contains(concat(' ',normalize-space(@class),' '),' comments-area ')])[last()]<\/code>\n<\/p>\n<p>\n  To get all element from that set after the 2nd one:\n<\/p>\n<p><code class=\"p\">(.\/\/div[@id='comments' and contains(concat(' ',normalize-space(@class),' '),' comments-area ')])[position()&gt;2]<\/code>\n<\/p>\n<p style=\"text-align:justify\">\n  If you familiar with <a href=\"https:\/\/css2xpath.github.io\/\" rel=\"nofollow noopener\" target=\"_blank\"><strong>CSS selectors it can be converted to XPath<\/strong><\/a> by this service.\n<\/p>\n<p style=\"text-align:justify\">\n  The samples above show the most used cases while setting up the product. More information about Xpath syntax can be found <a href=\"https:\/\/riptutorial.com\/xpath\" rel=\"nofollow noopener\" target=\"_blank\">here<\/a> and <a href=\"https:\/\/www.w3schools.com\/xml\/xpath_intro.asp\" rel=\"nofollow noopener\" target=\"_blank\">here<\/a>. And we can <a href=\"https:\/\/www.videlibri.de\/cgi-bin\/xidelcgi\" rel=\"nofollow noopener\" target=\"_blank\"><strong>test the selectors<\/strong><\/a> on a real markup.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An XPath selector is a powerful language to choose the specified set from the tags tree. While developing this product we wanted to use CSS selectors that simpler and more often use. But CSS doesn\u2019t allow to choose the item by index. Therefore, we decided to use XPath. E.g. we want to get all div&#8230;<\/p>\n","protected":false},"author":18,"featured_media":0,"parent":4812,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"rank_math_lock_modified_date":false},"categories":[816],"tags":[],"class_list":["post-4848","doc","type-doc","status-publish","hentry","category-accelerator"],"_links":{"self":[{"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/doc\/4848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/doc"}],"about":[{"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/types\/doc"}],"author":[{"embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/comments?post=4848"}],"up":[{"embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/doc\/4812"}],"wp:attachment":[{"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/media?parent=4848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/categories?post=4848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.s-sols.com\/api\/wp\/v2\/tags?post=4848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}