Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ia): reorg /web/xpath #37895

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
530 changes: 285 additions & 245 deletions files/en-us/_redirects.txt

Large diffs are not rendered by default.

164 changes: 82 additions & 82 deletions files/en-us/_wikihistory.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ This section lists `page-type` values for pages under [Web/Manifest](/en-US/docs

This section lists `page-type` values for pages under [Web/XPath](/en-US/docs/Web/XPath). Every page in that part of the tree must have a `page-type`, and its value must be one of those listed below or one of the [generic page type](#generic_page_types) values.

- `xpath-function`: a function, like [`ceiling()`](/en-US/docs/Web/XPath/Functions/ceiling)
- `xpath-function`: a function, like [`ceiling()`](/en-US/docs/Web/XPath/Reference/Functions/ceiling)

### XSLT page types

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/mozilla/firefox/releases/3.6/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Gecko 1.9.2 introduces JavaScript 1.8.2, which adds a number of language feature
### XPath

- The choose() XPath method is now supported
- : The [`choose()`](/en-US/docs/Web/XPath/Functions/choose) method is now supported by our implementation of [XPath](/en-US/docs/Web/XPath).
- : The [`choose()`](/en-US/docs/Web/XPath/Reference/Functions/choose) method is now supported by our implementation of [XPath](/en-US/docs/Web/XPath).

## For XUL and add-on developers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The DOM Level 2 views to HTML and XHTML documents are now unified per HTML 5.
- `document.createElementNS(null, "FOO")` no longer creates an HTML element node in HTML documents. `document.createElement("FOO")`
or `document.createElementNS("http://www.w3.org/1999/xhtml", "foo")` continue
to work in HTML documents.
- The [`name`](/en-US/docs/Web/XPath/Functions/name) and the [`local-name`](/en-US/docs/Web/XPath/Functions/local-name) functions in XPath returns the name of HTML elements in lower case. Previously, in HTML documents, they returned it in upper case.
- The [`name`](/en-US/docs/Web/XPath/Reference/Functions/name) and the [`local-name`](/en-US/docs/Web/XPath/Reference/Functions/local-name) functions in XPath returns the name of HTML elements in lower case. Previously, in HTML documents, they returned it in upper case.

The most probable upgrade problem is the pattern `if (elt.localName === "FOO")`.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/document/creatensresolver/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ createNSResolver(nodeResolver)
## See also

- {{domxref("Document.evaluate()")}}
- [Introduction to using XPath in JavaScript](/en-US/docs/Web/XPath/Introduction_to_using_XPath_in_JavaScript)
- [Introduction to using XPath in JavaScript](/en-US/docs/Web/XPath/Guides/Introduction_to_using_XPath_in_JavaScript)
2 changes: 1 addition & 1 deletion files/en-us/web/api/document/evaluate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ context node, document.body. If the "." was left out (leaving `//h2`) the
query would start from the root node (`html`) which would be more
wasteful.)

See [Introduction to using XPath in JavaScript](/en-US/docs/Web/XPath/Introduction_to_using_XPath_in_JavaScript) for more information.
See [Introduction to using XPath in JavaScript](/en-US/docs/Web/XPath/Guides/Introduction_to_using_XPath_in_JavaScript) for more information.

### Getting element by xml:id

Expand Down
18 changes: 0 additions & 18 deletions files/en-us/web/xpath/comparison_with_css_selectors/index.md

This file was deleted.

47 changes: 0 additions & 47 deletions files/en-us/web/xpath/functions/index.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Comparison of CSS selectors and XPath
short-title: CSS selectors and XPath
slug: Web/XPath/Guides/Comparison_with_CSS_selectors
page-type: guide
sidebar:
- xsltsidebar
---

This article seeks to document the difference between CSS selectors and XPath for web developers to be able to better choose the right tool for the right job.

| [XPath feature](/en-US/docs/Web/XPath) | [CSS equivalent](/en-US/docs/Web/CSS/CSS_selectors) |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [`ancestor`](/en-US/docs/Web/XPath/Reference/Axes#ancestor), [`parent`](/en-US/docs/Web/XPath/Reference/Axes#parent) or [`preceding-sibling`](/en-US/docs/Web/XPath/Reference/Axes#preceding-sibling) axis | {{CSSxRef(":has",":has()")}} selector |
| [`attribute`](/en-US/docs/Web/XPath/Reference/Axes#attribute) axis | [Attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors) |
| [`child`](/en-US/docs/Web/XPath/Reference/Axes#child) axis | [Child combinator](/en-US/docs/Web/CSS/Child_combinator) |
| [`descendant`](/en-US/docs/Web/XPath/Reference/Axes#descendant) axis | [Descendant combinator](/en-US/docs/Web/CSS/Descendant_combinator) |
| [`following-sibling`](/en-US/docs/Web/XPath/Reference/Axes#following-sibling) axis | [Subsequent-sibling combinator](/en-US/docs/Web/CSS/Subsequent-sibling_combinator) or [Next-sibling combinator](/en-US/docs/Web/CSS/Next-sibling_combinator) |
| [`self`](/en-US/docs/Web/XPath/Reference/Axes#self) axis | {{CSSxRef(":scope")}} or {{CSSxRef(":host")}} selector |
17 changes: 17 additions & 0 deletions files/en-us/web/xpath/guides/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: XPath guides
short-title: Guides
slug: Web/XPath/Guides
page-type: landing-page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
page-type: landing-page
page-type: listing-page

sidebar:
- xsltsidebar
---

This page lists guides for XPath.
They're intended to help you understand what kinds of things are possible using XPath in JavaScript, and highlight the similarities with CSS selectors.

{{SubPagesWithSummaries}}

## See also

- [XPath reference](/en-US/docs/Web/XPath/Reference)
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
title: Introduction to using XPath in JavaScript
slug: Web/XPath/Introduction_to_using_XPath_in_JavaScript
short-title: Using XPath in JavaScript
slug: Web/XPath/Guides/Introduction_to_using_XPath_in_JavaScript
page-type: guide
sidebar:
- xsltsidebar
---

{{XsltSidebar}}

This document describes the interface for using [XPath](/en-US/docs/Web/XPath) in JavaScript.
The main interface to using XPath is the [evaluate](/en-US/docs/Web/API/Document/evaluate) function of the [document](/en-US/docs/Web/API/Document) object.

Expand Down Expand Up @@ -81,7 +82,7 @@ We obtain the returned value of the expression by accessing the following proper

##### Example

The following uses the XPath expression [`count(//p)`](/en-US/docs/Web/XPath/Functions/count) to obtain the number of `<p>` elements in an HTML document:
The following uses the XPath expression [`count(//p)`](/en-US/docs/Web/XPath/Reference/Functions/count) to obtain the number of `<p>` elements in an HTML document:

```js
const paragraphCount = document.evaluate(
Expand Down Expand Up @@ -324,11 +325,11 @@ Another approach to match default elements in a non-null namespace (and one whic

If one wishes to provide flexibility in namespaces (as they are intended) by not necessarily requiring a particular prefix to be used when finding a namespaced element or attribute, one must use special techniques.

While one can adapt the approach in the above section to test for namespaced elements regardless of the prefix chosen (using [`local-name()`](/en-US/docs/Web/XPath/Functions/local-name) in combination with [`namespace-uri()`](/en-US/docs/Web/XPath/Functions/namespace-uri) instead of [`name()`](/en-US/docs/Web/XPath/Functions/name)), a more challenging situation occurs, however, if one wishes to grab an element with a particular namespaced attribute in a predicate (given the absence of implementation-independent variables in XPath 1.0).
While one can adapt the approach in the above section to test for namespaced elements regardless of the prefix chosen (using [`local-name()`](/en-US/docs/Web/XPath/Reference/Functions/local-name) in combination with [`namespace-uri()`](/en-US/docs/Web/XPath/Reference/Functions/namespace-uri) instead of [`name()`](/en-US/docs/Web/XPath/Reference/Functions/name)), a more challenging situation occurs, however, if one wishes to grab an element with a particular namespaced attribute in a predicate (given the absence of implementation-independent variables in XPath 1.0).

For example, one might try (incorrectly) to grab an element with a namespaced attribute as follows: `const xpathLink = someElements[local-name(@*)="href" and namespace-uri(@*)='http://www.w3.org/1999/xlink'];`

This could inadvertently grab some elements if one of its attributes existed that had a local name of `href`, but it was a different attribute which had the targeted (XLink) namespace (instead of [`@href`](/en-US/docs/Web/XPath/Axes#attribute)).
This could inadvertently grab some elements if one of its attributes existed that had a local name of `href`, but it was a different attribute which had the targeted (XLink) namespace (instead of [`@href`](/en-US/docs/Web/XPath/Reference/Axes#attribute)).

In order to accurately grab elements with the XLink `@href` attribute (without also being confined to predefined prefixes in a namespace resolver), one could obtain them as follows:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: XPath snippets
slug: Web/XPath/Snippets
slug: Web/XPath/Guides/Snippets
page-type: guide
sidebar:
- xsltsidebar
---

{{XsltSidebar}}

This article provides some XPath code snippets — simple examples of how to a few simple **utility functions** based on standard interfaces from the [DOM Level 3 XPath specification](https://www.w3.org/TR/DOM-Level-3-XPath/) that expose XPath functionality to JavaScript code. The snippets are functions you can use in the real world in your own code.

### Node-specific evaluator function
Expand Down Expand Up @@ -153,4 +153,4 @@ function getXPathForElement(el, xml) {

## See also

- [Introduction to using XPath in JavaScript](/en-US/docs/Web/XPath/Introduction_to_using_XPath_in_JavaScript)
- [Introduction to using XPath in JavaScript](/en-US/docs/Web/XPath/Guides/Introduction_to_using_XPath_in_JavaScript)
Loading