Skip to content

Commit

Permalink
convert to markdown for two sections
Browse files Browse the repository at this point in the history
  • Loading branch information
yin1999 committed Jul 19, 2022
1 parent 716ac78 commit 0435ca6
Show file tree
Hide file tree
Showing 7 changed files with 610 additions and 805 deletions.
91 changes: 31 additions & 60 deletions files/zh-cn/web/xpath/axes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,34 @@ tags:
- XPath_Reference
translation_of: Web/XPath/Axes
---
<p>{{ XsltRef() }} There are thirteen different axes in the <a href="cn/XPath">XPath</a> specification. An axis represents a relationship to the context node, and is used to locate nodes relative to that node on the tree. The following is an extremely brief description of the thirteen available axes and the degree of support available in <a href="cn/Gecko">Gecko</a>.</p>
<p>For further information on using XPath expressions, please see the <a href="cn/Transforming_XML_with_XSLT/For_Further_Reading">For Further Reading</a> section at the end of <a href="cn/Transforming_XML_with_XSLT">Transforming XML with XSLT</a> document.</p>
<p> </p>
<dl>
<dt>
<a href="cn/XPath/Axes/ancestor">ancestor</a></dt>
<dd>
Indicates all the ancestors of the context node beginning with the parent node and traveling through to the root node.</dd>
<dt>
<a href="cn/XPath/Axes/ancestor-or-self">ancestor-or-self</a></dt>
<dd>
Indicates the context node and all of its ancestors, including the root node.</dd>
<dt>
<a href="cn/XPath/Axes/attribute">attribute</a></dt>
<dd>
Indicates the attributes of the context node. Only elements have attributes. This axis can be abbreviated with the at sign (<code>@</code>).</dd>
<dt>
<a href="cn/XPath/Axes/child">child</a></dt>
<dd>
Indicates the children of the context node. If an XPath expression does not specify an axis, is understood by default. Since only the root node or element nodes have children, any other use will select nothing.</dd>
<dt>
<a href="cn/XPath/Axes/descendant">descendant</a></dt>
<dd>
Indicates all of the children of the context node, and all of their children, and so forth. Attribute and namespace nodes are <b>not</b> included - the <code>parent</code> of an <code>attribute</code> node is an element node, but <code>attribute</code> nodes are not the children of their parents.</dd>
<dt>
<a href="cn/XPath/Axes/descendant-or-self">descendant-or-self</a></dt>
<dd>
Indicates the context node and all of its descendants. Attribute and namespace nodes are <b>not</b> included - the <code>parent</code> of an <code>attribute</code> node is an element node, but <code>attribute</code> nodes are not the children of their parents.</dd>
<dt>
<a href="cn/XPath/Axes/following">following</a></dt>
<dd>
Indicates all the nodes that appear after the context node, except any <code>descendant</code>, <code>attribute</code>, and <code>namespace</code> nodes.</dd>
<dt>
<a href="cn/XPath/Axes/following-sibling">following-sibling</a></dt>
<dd>
Indicates all the nodes that have the same parent as the context node and appear after the context node in the source document.</dd>
<dt>
<a href="cn/XPath/Axes/namespace">namespace</a>
<i>
(not supported)</i>
</dt>
<dd>
Indicates all the nodes that are in scope for the context node. In this case, the context node must be an element node.</dd>
<dt>
<a href="cn/XPath/Axes/parent">parent</a></dt>
<dd>
Indicates the single node that is the parent of the context node. It can be abbreviated as two periods (<code>..</code>).</dd>
<dt>
<a href="cn/XPath/Axes/preceding">preceding</a></dt>
<dd>
Indicates all the nodes that precede the context node in the document except any <code>ancestor</code>, <code>attribute</code> and <code>namespace</code> nodes.</dd>
<dt>
<a href="cn/XPath/Axes/preceding-sibling">preceding-sibling</a></dt>
<dd>
Indicates all the nodes that have the same parent as the context node and appear before the context node in the source document.</dd>
<dt>
<a href="cn/XPath/Axes/self">self</a></dt>
<dd>
Indicates the context node itself. It can be abbreviated as a single period (<code>.</code>).</dd>
</dl>
{{ XsltRef() }} There are thirteen different axes in the [XPath](cn/XPath) specification. An axis represents a relationship to the context node, and is used to locate nodes relative to that node on the tree. The following is an extremely brief description of the thirteen available axes and the degree of support available in [Gecko](cn/Gecko).

For further information on using XPath expressions, please see the [For Further Reading](cn/Transforming_XML_with_XSLT/For_Further_Reading) section at the end of [Transforming XML with XSLT](cn/Transforming_XML_with_XSLT) document.

- [ancestor](cn/XPath/Axes/ancestor)
- : Indicates all the ancestors of the context node beginning with the parent node and traveling through to the root node.
- [ancestor-or-self](cn/XPath/Axes/ancestor-or-self)
- : Indicates the context node and all of its ancestors, including the root node.
- [attribute](cn/XPath/Axes/attribute)
- : Indicates the attributes of the context node. Only elements have attributes. This axis can be abbreviated with the at sign (`@`).
- [child](cn/XPath/Axes/child)
- : Indicates the children of the context node. If an XPath expression does not specify an axis, is understood by default. Since only the root node or element nodes have children, any other use will select nothing.
- [descendant](cn/XPath/Axes/descendant)
- : Indicates all of the children of the context node, and all of their children, and so forth. Attribute and namespace nodes are **not** included - the `parent` of an `attribute` node is an element node, but `attribute` nodes are not the children of their parents.
- [descendant-or-self](cn/XPath/Axes/descendant-or-self)
- : Indicates the context node and all of its descendants. Attribute and namespace nodes are **not** included - the `parent` of an `attribute` node is an element node, but `attribute` nodes are not the children of their parents.
- [following](cn/XPath/Axes/following)
- : Indicates all the nodes that appear after the context node, except any `descendant`, `attribute`, and `namespace` nodes.
- [following-sibling](cn/XPath/Axes/following-sibling)
- : Indicates all the nodes that have the same parent as the context node and appear after the context node in the source document.
- [namespace](cn/XPath/Axes/namespace)
_(not supported)_
- : Indicates all the nodes that are in scope for the context node. In this case, the context node must be an element node.
- [parent](cn/XPath/Axes/parent)
- : Indicates the single node that is the parent of the context node. It can be abbreviated as two periods (`..`).
- [preceding](cn/XPath/Axes/preceding)
- : Indicates all the nodes that precede the context node in the document except any `ancestor`, `attribute` and `namespace` nodes.
- [preceding-sibling](cn/XPath/Axes/preceding-sibling)
- : Indicates all the nodes that have the same parent as the context node and appear before the context node in the source document.
- [self](cn/XPath/Axes/self)
- : Indicates the context node itself. It can be abbreviated as a single period (`.`).
46 changes: 10 additions & 36 deletions files/zh-cn/web/xpath/comparison_with_css_selectors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,15 @@ slug: Web/XPath/Comparison_with_CSS_selectors
translation_of: Web/XPath/Comparison_with_CSS_selectors
original_slug: Web/CSS/CSS_Selectors/Comparison_with_XPath
---
<div>{{CSSRef("Selectors")}}{{QuickLinksWithSubpages("/en-US/docs/Web/XPath")}}</div>
{{CSSRef("Selectors")}}{{QuickLinksWithSubpages("/en-US/docs/Web/XPath")}}

<p>本文旨在记录 CSS 选择器和 XPath 之间的区别,以便 Web 开发人员能够更好地为正确的工作选择合适的工具。</p>
本文旨在记录 CSS 选择器和 XPath 之间的区别,以便 Web 开发人员能够更好地为正确的工作选择合适的工具。

<table class="standard-table">
<thead>
<tr>
<th scope="col"><a href="/en-US/docs/Web/XPath">XPath feature</a></th>
<th scope="col"><a href="/en-US/docs/Web/CSS/CSS_Selectors">CSS equivalent</a></th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="/en-US/docs/Web/XPath/Axes/ancestor"><code>ancestor</code></a>, <a href="/en-US/docs/Web/XPath/Axes/parent"><code>parent</code></a> or <a href="/en-US/docs/Web/XPath/Axes/preceding-sibling"><code>preceding-sibling</code></a> axis</td>
<td>{{CSSxRef(":has",":has()")}} selector {{experimental_inline}}</td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/XPath/Axes/ancestor"><code>attribute</code></a> axis</td>
<td><a href="/en-US/docs/Web/CSS/Attribute_selectors">Attribute selectors</a></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/XPath/Axes/child"><code>child</code></a> axis</td>
<td><a href="/en-US/docs/Web/CSS/Child_selectors">Child combinator</a></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/XPath/Axes/descendant"><code>descendant</code></a> axis</td>
<td><a href="/en-US/docs/Web/CSS/Descendant_selectors">Descendant combinator</a></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/XPath/Axes/following-sibling"><code>following-sibling</code></a> axis</td>
<td><a href="/en-US/docs/Web/CSS/General_sibling_selectors">General sibling combinator</a> or <a href="/en-US/docs/Web/CSS/Adjacent_sibling_selectors">adjacent sibling combinator</a></td>
</tr>
<tr>
<td><a href="/en-US/docs/Web/XPath/Axes/self"><code>self</code></a> axis</td>
<td>{{CSSxRef(":scope")}} or {{CSSxRef(":host")}} selector</td>
</tr>
</tbody>
</table>
| [XPath feature](/en-US/docs/Web/XPath) | [CSS equivalent](/en-US/docs/Web/CSS/CSS_Selectors) |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [`ancestor`](/en-US/docs/Web/XPath/Axes/ancestor), [`parent`](/en-US/docs/Web/XPath/Axes/parent) or [`preceding-sibling`](/en-US/docs/Web/XPath/Axes/preceding-sibling) axis | {{CSSxRef(":has",":has()")}} selector {{experimental_inline}} |
| [`attribute`](/en-US/docs/Web/XPath/Axes/ancestor) axis | [Attribute selectors](/en-US/docs/Web/CSS/Attribute_selectors) |
| [`child`](/en-US/docs/Web/XPath/Axes/child) axis | [Child combinator](/en-US/docs/Web/CSS/Child_selectors) |
| [`descendant`](/en-US/docs/Web/XPath/Axes/descendant) axis | [Descendant combinator](/en-US/docs/Web/CSS/Descendant_selectors) |
| [`following-sibling`](/en-US/docs/Web/XPath/Axes/following-sibling) axis | [General sibling combinator](/en-US/docs/Web/CSS/General_sibling_selectors) or [adjacent sibling combinator](/en-US/docs/Web/CSS/Adjacent_sibling_selectors) |
| [`self`](/en-US/docs/Web/XPath/Axes/self) axis | {{CSSxRef(":scope")}} or {{CSSxRef(":host")}} selector |
86 changes: 39 additions & 47 deletions files/zh-cn/web/xpath/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,42 @@ tags:
- XPath
translation_of: Web/XPath
---
<p>XPath 的意思是 XML 路径语言。它使用的一个非 XML 语法提供一种灵活地定位 <a href="/zh-CN/docs/XML">XML</a> 文档的不同部分的方法。它同时也可以用于检测文档中某个节点是否与某个模式(pattern)匹配。</p>

<p>XPath 主要被用于 <a href="/zh-CN/docs/XSLT">XSLT</a>,也可用于定位文档元素,像类 XML 语言文档(如 HTML 和 <a href="/zh-CN/docs/XUL">XUL</a> ) 通过 <a href="/zh-CN/docs/DOM">DOM</a> 定位元素一样。替代 {{Domxref("document.getElementById")}} 方法、 {{Domxref("element.childNodes")}} 属性和其他 DOM 核心特性。</p>

<p>XPath 使用路径标识符通过层级结构来导航 XML 文档。它使用非 XML 语法,以致于它可以被用在 URIs 和 XML 属性值上。</p>

<div class="note">
<p><strong>备注:</strong> XPath 的浏览器支持差别很大;Firefox 支持地相当不错 (尽管没有计划进一步提高支持),而其他浏览器则较小程度地实现了它。如果你需要一个兼容主流浏览器的 XPath,你可以考虑试试 <a href="http://nchc.dl.sourceforge.net/project/js-xpath/js-xpath/1.0.0/xpath.js">js-xpath</a> 或 <a href="https://github.com/google/wicked-good-xpath">wicked-good-xpath</a>.</p>
</div>

<h2 id="Documentation">文档</h2>

<dl>
<dt><a href="/zh-CN/docs/Introduction_to_using_XPath_in_JavaScript">在 JavaScript 中使用 XPath 的介绍</a></dt>
<dd>描述了 XPath 的一个非 XSLT 使用。</dd>
<dt><a href="/en-US/docs/XPath/Axes">XPath:Axes</a></dt>
<dd>List and definition of the axes defined in the XPath specification. Axes are used to describe the relationships between nodes.</dd>
<dt><a href="/en-US/docs/XPath/Functions">XPath:Functions</a></dt>
<dd>List and description of the core XPath functions and XSLT-specific additions to XPath.</dd>
<dt><a href="/en-US/docs/Transforming_XML_with_XSLT">Transforming XML with XSLT</a></dt>
<dd>XSLT uses XPath to address code segments in a XML document that it wishes to transform.</dd>
<dt><a href="/en-US/docs/Web/XPath/Snippets">XPath snippets</a></dt>
<dd>JavaScript utility functions to use in your own code, based on <a href="http://www.w3.org/TR/DOM-Level-3-XPath/">DOM Level 3 XPath </a>APIs.</dd>
<dt><a href="http://www.xml.com/pub/a/2000/08/holman/">What is XSLT?</a></dt>
<dd>This extensive introduction to XSLT and XPath assumes no prior knowledge of the technologies, and guides the reader through background, context, structure, concepts and introductory terminology.</dd>
<dt><a href="/en-US/docs/JXON">JXON</a></dt>
<dd><strong>JXON</strong> (lossless <strong>J</strong>avaScript <strong>X</strong>ML <strong>O</strong>bject <strong>N</strong>otation) is a generic name by which is defined the representation of JavaScript Objects using <a href="/en/XML">XML</a>. There are some cases in which the whole content of an XML document must be read from the JavaScript interpreter (like for web-apps languages or settings XML documents, for example). In these cases JXON could represent the most practical way and a valid alternative to XPath.</dd>
</dl>

<h2 id="Tools">工具</h2>

<dl>
<dt><a href="https://addons.mozilla.org/zh-CN/firefox/addon/1192">XPather</a></dt>
<dd>Feature rich XPath generator, editor, inspector, and simple extraction tool (FireFox Add-On).</dd>
<dt><a href="https://addons.mozilla.org/zh-CN/firefox/addon/11900">FireXPath</a></dt>
<dd>XPath panel that integrates tightly into FireBug, providing an editor and inspector (FireFox Add-On).</dd>
<dt><a href="http://qutoric.com/xmlquire/">XMLQuire (formerly known as SketchPath)</a></dt>
<dd>A Graphical XPath Builder/Debugger(.NET).</dd>
</dl>

<h2 id="Related_Topics">相关主题</h2>

<ul>
<li><a href="/zh-CN/docs/XSLT">XSLT</a>, <a href="/zh-CN/docs/XQuery">XQuery</a>, <a href="/zh-CN/docs/XML">XML</a>, <a href="/zh-CN/docs/DOM">DOM</a>, <a href="/zh-CN/docs/JXON">JXON</a>, <a href="/zh-CN/docs/JSON/JSONPath">JSONPath</a></li>
</ul>

<div>{{QuickLinksWithSubpages("/zh-CN/docs/Web/XPath")}}</div>
XPath 的意思是 XML 路径语言。它使用的一个非 XML 语法提供一种灵活地定位 [XML](/zh-CN/docs/XML) 文档的不同部分的方法。它同时也可以用于检测文档中某个节点是否与某个模式(pattern)匹配。

XPath 主要被用于 [XSLT](/zh-CN/docs/XSLT),也可用于定位文档元素,像类 XML 语言文档(如 HTML 和 [XUL](/zh-CN/docs/XUL) ) 通过 [DOM](/zh-CN/docs/DOM) 定位元素一样。替代 {{Domxref("document.getElementById")}} 方法、 {{Domxref("element.childNodes")}} 属性和其他 DOM 核心特性。

XPath 使用路径标识符通过层级结构来导航 XML 文档。它使用非 XML 语法,以致于它可以被用在 URIs 和 XML 属性值上。

> **备注:** XPath 的浏览器支持差别很大;Firefox 支持地相当不错 (尽管没有计划进一步提高支持),而其他浏览器则较小程度地实现了它。如果你需要一个兼容主流浏览器的 XPath,你可以考虑试试 [js-xpath](http://nchc.dl.sourceforge.net/project/js-xpath/js-xpath/1.0.0/xpath.js)[wicked-good-xpath](https://github.com/google/wicked-good-xpath).
## 文档

- [在 JavaScript 中使用 XPath 的介绍](/zh-CN/docs/Introduction_to_using_XPath_in_JavaScript)
- : 描述了 XPath 的一个非 XSLT 使用。
- [XPath:Axes](/en-US/docs/XPath/Axes)
- : List and definition of the axes defined in the XPath specification. Axes are used to describe the relationships between nodes.
- [XPath:Functions](/en-US/docs/XPath/Functions)
- : List and description of the core XPath functions and XSLT-specific additions to XPath.
- [Transforming XML with XSLT](/en-US/docs/Transforming_XML_with_XSLT)
- : XSLT uses XPath to address code segments in a XML document that it wishes to transform.
- [XPath snippets](/en-US/docs/Web/XPath/Snippets)
- : JavaScript utility functions to use in your own code, based on [DOM Level 3 XPath ](http://www.w3.org/TR/DOM-Level-3-XPath/)APIs.
- [What is XSLT?](http://www.xml.com/pub/a/2000/08/holman/)
- : This extensive introduction to XSLT and XPath assumes no prior knowledge of the technologies, and guides the reader through background, context, structure, concepts and introductory terminology.
- [JXON](/en-US/docs/JXON)
- : **JXON** (lossless **J**avaScript **X**ML **O**bject **N**otation) is a generic name by which is defined the representation of JavaScript Objects using [XML](/en/XML). There are some cases in which the whole content of an XML document must be read from the JavaScript interpreter (like for web-apps languages or settings XML documents, for example). In these cases JXON could represent the most practical way and a valid alternative to XPath.

## 工具

- [XPather](https://addons.mozilla.org/zh-CN/firefox/addon/1192)
- : Feature rich XPath generator, editor, inspector, and simple extraction tool (FireFox Add-On).
- [FireXPath](https://addons.mozilla.org/zh-CN/firefox/addon/11900)
- : XPath panel that integrates tightly into FireBug, providing an editor and inspector (FireFox Add-On).
- [XMLQuire (formerly known as SketchPath)](http://qutoric.com/xmlquire/)
- : A Graphical XPath Builder/Debugger(.NET).

## 相关主题

- [XSLT](/zh-CN/docs/XSLT), [XQuery](/zh-CN/docs/XQuery), [XML](/zh-CN/docs/XML), [DOM](/zh-CN/docs/DOM), [JXON](/zh-CN/docs/JXON), [JSONPath](/zh-CN/docs/JSON/JSONPath)

{{QuickLinksWithSubpages("/zh-CN/docs/Web/XPath")}}
Loading

0 comments on commit 0435ca6

Please sign in to comment.