calibre - en to zh_CN translation catalogue (23 entries)

en: XPath tutorial
zh_CN: XPath教程

en: In this tutorial, you will be given a gentle introduction to `XPath <https://en.wikipedia.org/wiki/XPath>`_, a query language that can be used to select arbitrary parts of `HTML <https://en.wikipedia.org/wiki/HTML>`_ documents in calibre. XPath is a widely used standard, and googling it will yield a ton of information. This tutorial, however, focuses on using XPath for e-book related tasks like finding chapter headings in an unstructured HTML document.
zh_CN: 在本教程中，将对`XPath <https://en.wikipedia.org/wiki/XPath>`_进行简要介绍，这是一种查询语言，在cllibre中可用于选择`HTML<https://en.wikipedia.org/wiki/HTML>`_文档的任意部分。 XPath是一种广泛使用的标准，并且对其进行谷歌搜索将产生大量信息。 但是，本教程重点介绍如何将XPath用于与电子书相关的任务，例如在非结构化HTML文档中查找章节标题。

en: Contents
zh_CN: 目录

en: Selecting by tag name
zh_CN: 按标记名选取

en: The simplest form of selection is to select tags by name. For example, suppose you want to select all the ``<h2>`` tags in a document. The XPath query for this is simply::
zh_CN: 最简单的选择形式是按名称选择 标记。例如，假设您要选择文档中的所有``<h2>``标签。针对此的XPath查询简单地为：

en: The prefix `//` means *search at any level of the document*. Now suppose you want to search for ``<span>`` tags that are inside ``<a>`` tags. That can be achieved with::
zh_CN: 前缀`//` 表示“在文档的任何级别搜索”。现在假设您要搜索``<a>``标记内的``<span>`` 标记。这可以通过以下方式实现：

en: If you want to search for tags at a particular level in the document, change the prefix::
zh_CN: 如果要搜索文档中特定级别的 标记，请更改前缀：

en: This will match only ``<p>A very short e-book to demonstrate the use of XPath.</p>`` in the :ref:`sample_ebook` but not any of the other ``<p>`` tags. The ``h:`` prefix in the above examples is needed to match XHTML tags. This is because internally, calibre represents all content as XHTML. In XHTML tags have a *namespace*, and ``h:`` is the namespace prefix for HTML tags.
zh_CN: 这将仅与"样本_电子书"中的“<p>A非常简短的电子书来演示XPath。</p>的使用”匹配，而不与其他任何“<p>” 标记匹配。上面示例中的“h:”前缀需要匹配XHTML标签。这是因为在内部，Calibre将所有内容表示为XHTML。在XHTML标签中，有一个*命名空间*，而且“h:”是HTML标签的命名空间前缀。

en: Now suppose you want to select both ``<h1>`` and ``<h2>`` tags. To do that, we need a XPath construct called *predicate*. A :dfn:`predicate` is simply a test that is used to select tags. Tests can be arbitrarily powerful and as this tutorial progresses, you will see more powerful examples. A predicate is created by enclosing the test expression in square brackets::
zh_CN: 现在假设您要同时选择“<h1>”和“<h2>” 标记。为此，我们需要一个称为*谓词*的XPath结构。A：“谓词”只是一个用于选择标签的测试。测试可以是任意强大的，随着本教程的进行，您将看到更强大的示例。谓词是通过将测试表达式括在方括号中创建的：

en: There are several new features in this XPath expression. The first is the use of the wildcard ``*``. It means *match any tag*. Now look at the test expression ``name()='h1' or name()='h2'``. :term:`name()` is an example of a *built-in function*. It simply evaluates to the name of the tag. So by using it, we can select tags whose names are either `h1` or `h2`. Note that the :term:`name()` function ignores namespaces so that there is no need for the ``h:`` prefix. XPath has several useful built-in functions. A few more will be introduced in this tutorial.
zh_CN: 此XPath表达式中有几个新功能。第一个是通配符“*”的使用。它的意思是*匹配任何标签*。现在看一下测试表达式“name()='h1'或name()='h2'”。“名称()”是一个*内置函数*的例子。 它只是评估标签的名称。 因此通过使用它，我们可以选择名称为“h1”或“h2”的标签。注意：“名称()”函数忽略命名空间，因此不需要“h:”前缀。XPath有几个有用的内置函数。本教程还将介绍更多内容。

en: Selecting by attributes
zh_CN: 按属性选择

en: To select tags based on their attributes, the use of predicates is required::
zh_CN: 要根据属性选择标签，需要使用谓词：

en: Here, the ``@`` operator refers to the attributes of the tag. You can use some of the `XPath built-in functions`_ to perform more sophisticated matching on attribute values.
zh_CN: 这里的“@”操作符指的是标签的属性。 您可以使用某些“XPath内置函数”_对属性值执行更复杂的匹配。

en: Selecting by tag content
zh_CN: 按标签内容选择

en: Using XPath, you can even select tags based on the text they contain. The best way to do this is to use the power of *regular expressions* via the built-in function :term:`re:test()`::
zh_CN: 使用XPath，您甚至可以根据标签中包含的文本选择标签。 最好的方法是通过内置函数“re:test()”使用*正则表达式*的功能：

en: Here the ``.`` operator refers to the contents of the tag, just as the ``@`` operator referred to its attributes.
zh_CN: 这里的``.``运算符指代标签的内容，就像``@``运算符指代标签的属性一样。

en: Sample e-book
zh_CN: 电子书样本

en: XPath built-in functions
zh_CN: XPath内置函数

en: name()
zh_CN: 名称()

en: The name of the current tag.
zh_CN: 当前标记的名称。

en: contains()
zh_CN: 包含（）

en: ``contains(s1, s2)`` returns `true` if s1 contains s2.
zh_CN: 如果s1包含s2，``contains(s1, s2)`` 返回 `true`

en: ``re:test(src, pattern, flags)`` returns `true` if the string `src` matches the regular expression `pattern`. A particularly useful flag is ``i``, it makes matching case insensitive. A good primer on the syntax for regular expressions can be found at `regexp syntax <https://docs.python.org/library/re.html>`_
zh_CN: 如果字符串`src`与正则表达式`pattern`匹配，则``re:test(src, pattern, flags)``返回true。一个特别有用的标志是``i``，它使匹配不区分大小写。有关正则表达式语法的入门知识，请参见“正则表达式语法<https://docs.python.org/library/re.html>”_。
