What does * in XPath

 

Summary

The XPath language is used to address parts of an XML document. It was designed for use in both XSLT and XPointer.

Status of this document

This document has been reviewed by members of the W3C and other interested parties and approved by the Director as a W3C recommendation. It is a closed document and may be used as reference material or cited as a normative reference from another document. The role of the W3C in making this advisory is to publicize the specification and promote its wide use. This increases the functionality and interoperability of the web.

The list of known errors in this specification is available at http://www.w3.org/1999/11/REC-xpath-19991116-errata.

Comments on this specification can be sent to [email protected]; all comments are available in an archive.

The English version of this specification is the only normative version. However, translations of this document are listed at http://www.w3.org/Style/XSL/translations.html.

Current W3C recommendations and other technical documents can be found at http://www.w3.org/TR.

This specification is the result of the joint work of the XSL and XML Linking Working Groups and is therefore part of the W3C Style Activity and the W3C XML Activity.

Table of Contents

1 Introduction
2 localization paths
2.1 Localization Steps
2.2 axes
2.3 Node Tests
2.4 Predicates
2.5 Abbreviated syntax
3 expressions
3.1 Basics
3.2 Function calls
3.3 Node sets
3.4 Boolean values
3.5 numbers
3.6 Strings
3.7 Lexical structure
4 Library of basic functions
4.1 Functions on sets of nodes
4.2 String functions
4.3 Boolean functions
4.4 Number functions
5 data model
5.1 Root node
5.2 Element nodes
5.2.1 Unique IDs
5.3 Attribute nodes
5.4 Namespace nodes
5.5 Processing Instruction Node
5.6 Comment nodes
5.7 Text nodes
6 conformity

attachment

A references
A.1 Normative references
A.2 Other references
B Mapping to the XML information volume (non-normative)

1 Introduction

XPath is the result of efforts to provide a common syntax and semantics for those functions that are used by both XSL Transformations [XSLT] and XPointer [XPointer]. The primary task of XPath is to address parts of an XML document [XML]. Simple tools for manipulating strings, numbers, and Boolean values ​​are also provided to support this task. XPath uses a compact, non-XML syntax to facilitate the use of XPath expressions within URIs and XML attributes. XPath operates on the abstract, logical structure of an XML document, not on its external syntax. XPath gets its name from the use of a path notation, which is also used in URLs, with which it is possible to navigate through the hierarchical structure of an XML document.

In addition to being used for addressing, XPath was designed in such a way that a natural subset of it can be used for matching (testing whether a node matches a pattern). This use of XPath is described in XSLT.

Translator's note:

This subset is called a pattern in XSLT. Although these patterns are defined by their own grammar, each pattern is also an XPath expression.

In addition to XSLT and XPointer, there are other specifications that use XPath. An example is the working draft of the W3C for the XML query language XQuery [XQuery], whose syntax uses extended XPath expressions.

XPath models an XML document as a tree that consists of nodes. There are different types of nodes, including element nodes, attribute nodes, and text nodes. XPath defines how the string value is calculated for each node type. Some nodes also have a name. XPath fully supports XML namespaces. Therefore, the name of a node is modeled as a pair of a local component and a possibly empty namespace URI - this is called an extended name. The data model is detailed in [5 data model] described.

Translator's note:

The following example is intended to illustrate the tree structure modeled by XPath:

<?xml version="1.0"?> <!DOCTYPE rezept SYSTEM "rezept.dtd"> <?xml-stylesheet href="style.xsl" type="text/xml"?> <rezept> <zutat id="mehl">200g Mehl</zutat> <!-- weitere Zutaten --> <anleitung> Zuerst nehmen Sie das <zutat xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="mehl">Mehl</zutat> und mischen es mit ... </anleitung> </rezept>

This rather short XML document already has a tree representation consisting of 23 nodes:

The XML declaration and the document type declaration cannot be found in the tree view, and they cannot be accessed via an XPath expression. All other components of the document (root, elements, text content, attributes, namespaces, comments, processing instructions) are represented by corresponding nodes in the tree. The empty squares symbolize text nodes that only contain white space characters. The extent to which such white space can be found in separate text nodes is determined by the application using XPath. Finally, attention should be drawn to the namespace nodes for the namespace that are implicitly associated with each element.

The Document Object Model [DOM] also defines a tree representation, which, however, differs in some points from the one used in XPath. These differences are referred to within the chapter [5 data model] received.

The primary syntactic construct in XPath is the expression. An expression can be derived from the production Expr. Evaluation of an expression results in an object that belongs to one of the following four basic types:

  • node-set (a disordered set of nodes with no duplicates)
  • boolean (true or not correct)
  • number (a floating point number)
  • string (a string consisting of UCS characters)

Translator's note:

These are the four basic types that XPath defines. In fact, specifications based on this can define further types, so that the evaluation of an XPath expression can result in an object of this new type. In particular, variables contained in the expression can accept objects of other types.

As you can see, there is no data type for nodes. A single node can, however, be used as a node set (node-set) that contains exactly one element.

The UCS characters (Universal Multiple-Octet Coded Character Set) permitted within character strings are described in [ISO / IEC 10646] and [ISO / IEC 10646, 2nd Edition].

An expression is always evaluated in terms of a context. XSLT and XPointer specify how this context is determined when using XPath expressions in XSLT or XPointer. The context consists of:

  • a node (the Context node)
  • a pair of positive integers not equal to 0 (the Context position and the Context size)
  • a lot of variable assignments
  • a function library
  • the namespace declarations in the scope of which the expression is located

The context position is always less than or equal to the context size.

The variable assignments consist of a mapping of variable names to variable values. The value of a variable is an object which can be of any type that is possible for expressions. Other types that are not specified here are also possible.

Translator's note:

For example, in the XSLT 1.0 specification [XSLT], the new type Results subtree (result tree fragment) introduced. Values ​​of this type arise as a result of the transformation process. The following variable declaration, for example, creates a variable named, the value of which is a Results subtree is:

<xsl:variable name="antwort"> <antwort><xsl:value-of select="6 * 7" /></antwort> </xsl:variable>

This type will probably no longer exist in future XSLT versions, since the result of a transformation will then be a normal set of nodes of the type node-set will be, see [XSLT 2.0].

The following statement, on the other hand, creates a variable whose value is derived from the calculation of an XPath expression expression results in:

At this point it should be noted that the generation of the variable assignments for and is an XSLT language element. XPath itself does not provide any constructs for this. Besides owns XSLT for this purpose.

The XPointer specification [XPointer], which also uses XPath, does not provide any options for creating variable assignments. The use of variable references within an XPointer expression therefore leads to a syntactic error. The query language for XML documents XQuery [XQuery] presented as a working draft of the W3C uses so-called FLWR expressions (pronounced "flower", an abbreviation for -, -, - and - clauses) to generate variable assignments.

Other specifications based on XPath must define in an analogous way how variable assignments are generated for a context.

The function library consists of a mapping of function names to functions. Each function has zero or more arguments and returns a single value. This specification defines a library of basic functions that must be supported by all XPath implementations (see [4 Library of basic functions]). In the case of a basic function, the arguments and the result belong to one of the four basic types. Both XSLT and XPointer extend XPath with additional functions, some of which operate on the four basic types, others on additional types defined by XSLT and XPointer.

Namespace declarations consist of mapping prefixes to namespace URIs.

Translator's note:

Assume that an element contains the following namespace declaration in its start tag:. A context for which this declaration is valid then contains a mapping of the prefix to the URI.

The variable assignments, the function library and the namespace declarations that are used to calculate a partial expression are always the same as those used for the surrounding expression. The context node, the context position and the context size which are used to calculate a partial expression, on the other hand, are sometimes different from those of the surrounding expression. Several types of expressions change the context node, but only predicates change the context position and size (see [2.4 Predicates]). When describing how certain expressions are to be calculated, it is always explicitly stated whether the context node, the context position or the context size changes when calculating partial expressions. If nothing is stated about the context node, context position and context size, they remain the same when calculating partial expressions of these expressions.

Translator's note:

To explain, here is a little anticipation:

Within a localization path, each step changes the context node that is relevant for the calculation of the following steps. A predicate filters nodes out of a node set so that the context size is usually reduced and the position of the filtered nodes changes accordingly.

XPath expressions often appear in XML attributes. The grammar specified in this section is applied to attribute values ​​after they have been normalized according to XML 1.0. For example, if the grammar uses the character, it must not appear in the XML source as, but must be noted in accordance with the XML 1.0 rules, for example by entering as. Within expressions, character string literals are delimited by single or double quotation marks, which are also used to delimit XML attributes. To avoid that a quotation mark within an expression is interpreted by the XML processor as the termination of the attribute value, the quotation mark can be entered as a character reference (or). Alternatively, single quotation marks can be used in the expression if the XML attribute is delimited by double quotation marks or vice versa.

Translator's note:

Instead of "character reference" it must be called "entity reference".

That being said, there are still cases where this simple recipe is not enough - namely, when a character string is required that should contain both types of quotation marks.

Suppose you want to test whether the content of the element matches the string "She asked:" How are you? "" If you want to limit this character string within an XPath expression with double quotation marks, you might get the idea of ​​writing the following using the entity reference, for example:

para = "She asked: & quot; How are you? & quot;"

However, this is not a solution, as an XML parser that parses this string resolves entity references. An XPath processor on top of it can no longer differentiate between "" "and" ", because the next step is to further formulate it

<xsl:if test='para="Sie fragte: &quot;Wie geht&apos;s?&quot;"'>

(this line is well-formed in the XML sense), this leads to an error in the XPath processor, as it still evaluates the following character string:

para = "She asked:" How are you? ""

A simple solution for such cases is to define the relevant character string as the value of a variable, for example in XSLT via

<xsl:variable name="string">Sie fragte: "Wie geht's?"</xsl:variable>

and then use this variable in XPath expressions.

<xsl:if test="para=$string">

Alternatively, the desired character string can be composed of several parts (using the function to be explained below concat), where each substring contains only one kind of quotation mark:

para = concat ('You asked: "How are you'," '",' s?" ')

The quotation mark that is used to delimit this expression within an attribute value must then be replaced by the associated entity reference.The result looks confusing, but is syntactically correct:

<xsl:if test="para=concat('Sie fragte: &quot;Wie geht', &quot;'&quot;, 's?&quot;')">

This second variant must be used when variables are not allowed, for example within an XSLT pattern or as part of an XPointer.

An important special term is the localization path. A location path selects a set of nodes relative to a context node. The result of computing an expression that is a localization path is precisely the node set that contains the nodes selected by the localization path. Location paths can contain recursive expressions that are used to filter sets of nodes. A localization path can be derived from the Production LocationPath.

The nonterminal QName and NCName used in the following grammar are defined in [XML Names], S is defined in [XML]. The grammar uses the same EBNF notation as in [XML] (with the exception that grammar symbols always start with a capital letter).

Translator's note:

The Extended Backus-Naur Form (EBNF) is used for the notation of formal grammars. It is explained in more detail in the Notation of the XML Specification [XML, 2nd Edition] chapter.

Expressions are parsed by breaking the character string into individual tokens and then parsing the resulting string of tokens. Whitespace characters can be used anywhere between tokens. The decomposition process is described in [3.7 Lexical structure] described.

Translator's note:

A token is a syntactic unit of characters, such as the name "", the number "" or the operator "". According to the XML specification, the spaces allowed between these tokens are sequences of spaces (# x20), tabs (# x9), line feeds (#xA) and carriage returns (#xD). Such white space characters may not appear within a token, e.g. not between the two individual characters "" and "" of the operator "".

2 localization paths

Although localization paths are not the most general grammatical construct in the language (a localization path is a special case of an expression), they are the most important construct and are therefore described first.

Each localization path can be expressed using straightforward and more verbal syntax. There are also a number of syntactic abbreviations with which frequent cases can be expressed briefly and concisely. This section explains the semantics of localization paths using the detailed syntax. The abbreviated syntax is then explained by showing how it is mapped to the detailed syntax (see [2.5 Abbreviated syntax]).

Here are some examples of localization paths using the verbose syntax:

  • selects the children of the context node.

  • selects all children of the context node.

  • selects all text nodes that are children of the context node.

  • selects all child nodes of the context node, regardless of their node type.

    Translator's note:

    Although all XPath localization paths can be used for context nodes of any type, it must be pointed out at this point that only the root node and element nodes can have children. These children can be element, text, comment and processing instruction nodes. Attribute and namespace nodes are never children of other nodes. This concept is discussed in detail again in Chapter [5 data model] described.

  • selects the attribute of the context node.

  • selects all attributes of the context node.

    Translator's note:

    These two expressions only make sense if the context node is an element node. For all other node types they return the empty node set.

  • selects the elements that are descendants of the context node.

  • selects all elements that are ancestors of the context node.

  • selects all ancestors of the context node as well as the context node itself, if it is an element.

  • selects all descendants of the context node, as well as the context node itself, if it is an element.

  • selects the context node if it is an element and nothing else.

  • selects the elements that are descendants of the children of the context node.

  • selects all grandchildren of the context node.

  • selects the root of the document (this is always the father of the document element).

    Translator's note:

    The term root differs here from the one used in the XML specification [XML, 2nd Edition]. There, the root and the document element denote the same thing. In XPath terminology, the document element is a child of the root node. The root node thus corresponds to Document entity, please refer [5.1 Root node]. This is important insofar as the root node can also have comment or processing instruction nodes as children, which are thus siblings of the document element.

    Furthermore, it must be added here that the root of the document is used to select in which the context node is located. It is easy to create a node set that contains nodes from different documents. The function defined in XSLT document returns, for example, the root node of another document.

  • selects all elements contained in the same document as the context node.

    Translator's note:

    Strictly speaking, all elements that are descendants of the root of the document to which the context node belongs are selected.

  • selects all elements that have a parent element and that are in the same document as the context node.

    Translator's note:

    The following examples show localization paths in which the originally selected node sets are further restricted by trailing filter expressions in square brackets, so-called predicates.

  • selects the first child element of the context node.

  • selects the last child element of the context node.

  • selects the penultimate child element of the context node.

  • selects all children of the context node, with the exception of the first child element of the context node.

  • selects the next sibling of the context node.

  • selects the previous sibling element of the context node.

    Translator's note:

    At this point, as a brief anticipation, it should be noted that the position of a node in the current context node list is via the function position can be determined and this position obviously depends on the viewing direction. The immediate predecessor of all previous sibling elements is in position 1.

  • selects the forty-second element in the document.

    Translator's note:

    All descendants of the root node are considered here. Based on their natural order in the document, the forty-second is selected from the total set. The definition of this natural order, the so-called document order, is part of the chapter [5 data model].

  • selects the second element of the fifth element of the document element.

  • selects all child elements of the context node that have an attribute with the value.

  • selects the fifth child element of the context node that has an attribute with the value.

  • selects the fifth child element of the context node if this child has an attribute with the value.

    Translator's note:

    The last two examples show how a predicate can change context size and position. The predicate always returns a node set that contains a maximum of one node, depending on whether there is a fifth node or not. The first of the two examples first restricts the node set under consideration to the elements with the attribute and then selects the fifth from these. The second example first selects the fifth element and then selects the nodes with the desired attribute from the remaining node set. If the fifth element does not have an attribute at the moment, the result in this case is the empty node set.

  • selects the -child elements of the context node that have at least one -child element with a string value equal to.

  • selects the -child elements of the context node that have one or more -child elements.

  • selects the and children of the context node.

    Translator's note:

    Here, from all children () those who are themselves () either an element or an element are selected. You have to be careful here, because the expression in the square brackets is evaluated for a different context node than the expression in front of the brackets. The comparison with the two previous examples shows the difference. The exact definition follows in chapter [2.4 Predicates].

  • selects the last or child element of the context node.

    Translator's note:

    Here the set of all - or - children is first considered and then the last one is selected from this. The result node set thus contains (at most) one node.

There are two types of localization paths: relative and absolute localization paths.

A relative localization path is formed by a sequence of one or more localization steps that are separated from one another by. The steps of a relative localization path are put together from left to right. Each step in turn selects a set of nodes relative to a context node. An initial sequence of steps is composed as follows with a following step: The initial sequence of steps selects a node set relative to a context node. Each node in this set is then used as a context node for the following step. The node sets determined by this step are merged. The union is then exactly the set of nodes that is selected by putting the steps together. For example, the -child selects the -children of the context node, or - in other words - the -children that have -parent elements.

An absolute localization path consists of the character and an optionally following relative localization path. One alone selects the root node of the document containing the context node. If a relative localization path follows, the localization path selects the node set which a relative localization path would select relative to the root node of the document containing the context node.

Translator's note:

A comparison with paths in the file system is useful here: both in UNIX operating systems and within URLs, the slash »« is used as a separator within file paths. Similarly, one can think of paths in an XML tree. A relative path always starts from the current node (the context node), an absolute path always starts at the document root. Strictly speaking, an absolute path is also relative, namely to the document of the context node. This plays a role when processing nodes from multiple documents.

However, one should be aware of one subtlety: while for example "" in a file system addresses exactly one file, precisely the one that has the name "" and is located in the subdirectory "", an analog XPath always selects a set of nodes, which can usually contain several nodes. But this shouldn't be surprising, as an element can have several child elements with the same name.

Localization paths

Translator's note:

The above grammar formally reproduces what has been described so far. As you can see, localization paths can also contain abbreviated components. These are discussed in chapter [2.5 Abbreviated syntax] described.

2.1 Localization Steps

A localization step has three components:

  • an axis specifying the relationship between the nodes selected by the locating step and the context node within the tree,

  • a node test that specifies the node type and expanded name of the nodes selected by the localization step, and

  • zero or more predicates that can be used to further refine the node set selected by the localization step using any expressions.

    Translator's note:

    Predicates in the mathematical sense are statements about properties that can be true or false for the objects in question. In this sense, a predicate selects precisely those nodes from a node set for which the corresponding statement applies. But even without knowledge of the conceptual world of predicate logic, one can use the terms "predicate wine" or "predicate examination" to clarify that a certain property or quality of the described object is expressed here.

The syntax of a localization step consists of the name of the axis, followed by two colons and the node test, followed by zero or more expressions enclosed in square brackets. For example, contains the axis, the node test and a predicate.

The set of nodes selected by the localization path results from the set of initial nodes determined by the axis and the node test, in that the individual predicates are applied there one after the other.

The output node set contains all nodes which are related to the context node in the relationship indicated by the axis and which have the node type and extended name specified in the node test. For example, the locating step selects all descendants of the context node: states that every node in the parent node set must be a descendant of the context node; states that every node in the starting node set must be an element with the name. The available axes are shown in [2.2 axes], the available node tests in [2.3 Node Tests]. The importance of some node tests depends on the axis.

The initial set of nodes is filtered by the first predicate and results in a new set of nodes. This is then filtered through the second predicate and so on. The resulting node set is ultimately the node set selected by the localization step. The axis affects how the expression is calculated in each predicate. The semantics of a predicate are thus defined with respect to an axis (see [2.4 Predicates]).

Translator's note:

This last sentence relates to predicates that evaluate the context position and thus the proximity position of the filtered nodes.

To clarify the procedure in the case of several predicates, refer to the two examples already discussed

child :: para [attribute :: type = "warning"] [position () = 5]

and

child :: para [position () = 5] [attribute :: type = "warning"]

in chapter [2 localization paths] referenced.

Localization steps

2.2 axes

The following axes are available:

  • The axis contains the children of the context node.

    Translator's note:

    The circles that are used here and on the following axes to represent the individual nodes do not represent any special node types. It could be elements as well as text nodes, comments or processing instructions. However, they never represent attribute or namespace nodes, as these can only be reached via specially defined axes. In particular, they are not children of other nodes.

    The numbers indicate the proximity position of the nodes in the node set selected by the axis.

  • The axis contains the descendants of the context node; a descendant is a child or a child of a child, and so on. The descendant axis never contains attribute or namespace nodes.

    Translator's note:

  • The axis contains the parent node of the context node, if there is one.

    Translator's note:

    With the exception of the root node, every node has a parent node.

  • The axis contains the ancestors of the context node; the ancestors of the context node consist of the parent node of the context node, its parent node, etc. The ancestor axis therefore always contains the root node, unless the context node itself is the root node.

    Translator's note:

  • The axis contains all subsequent siblings of the context node; if the context node is an attribute or namespace node, this axis is empty.

    Translator's note:

    Siblings are the nodes that have the same parent node as the context node.

  • The axis contains all previous siblings of the context node; if the context node is an attribute or namespace node, this axis is empty.

    Translator's note:

  • The axis contains all nodes in the same document as the context node that occur after the context node in document order, without its descendants and without attribute and namespace nodes.

    Translator's note:

  • The axis contains all nodes in the same document as the context node that occur before the context node in document order, without its ancestors and without attribute and namespace nodes.

    Translator's note:

  • The axis contains the attributes of the context node; this axis is empty unless the context node is an element node.

  • The axis contains all namespace nodes of the context node; this axis is empty unless the context node is an element node.

  • The axis only contains the context node itself.

    Translator's note:

  • The axis contains the context node and the descendants of the context node.

    Translator's note:

  • The axis contains the context node and the ancestors of the context node; this axis therefore always contains the root node.

    Translator's note:

Annotation: The axes,,, and partition a document (omitting the attribute and namespace nodes): they do not overlap and together contain all the nodes of the document.

Translator's note:

axes
[6]    AxisName   ::=   'ancestor'
| 'ancestor-or-self'
| 'attribute'
| 'child'
| 'descendant'
| 'descendant-or-self'
| 'following'
| 'following-sibling'
| 'namespace'
| 'parent'
| 'preceding'
| 'preceding-sibling'
| 'self'

Translator's note:

Attribute and namespace axes play a special role here. The addressed nodes are characterized by a certain fixed node type (the so-called main node type). Since these nodes are by definition not children of other nodes, the special axes and have been defined. Nevertheless, any node test can also be carried out on these axes (see [2.3 Node Tests]). This harbors the risk that while syntactically correct but pointless localization steps can be used that never select a node. The localization step, which is to select a text node via the attribute axis, always delivers an empty node set, for example.

2.3 Node Tests

Each axis has one Major node type. If an axis can contain elements, the main node type is the element type, otherwise it is exactly the type of node that the axis can contain. That means:

  • For the attribute axis, the main node type is the attribute type.
  • For the namespace axis, the main node type is the namespace type.
  • For all other axes, the main node type is the element type.

A node test that is a QName is met if and only if the node type (see [5 data model]) is the main node type and has an expanded name that is the same as the expanded name of the QName. For example, selects the children of the context node. If the context node has no children, the result is an empty node set. selects the attributes of the context node. If the context node has no attributes, the result is an empty node set.

Translator's note:

The acronym QName stands for "qualified name" and means that the corresponding name can consist of an optional prefix and a local part. Both parts are separated from each other by a colon. The namespace to which the local name belongs is determined by the prefix. In the example, the prefix and the local component are. The above examples use node tests, which are ultimately only local names, i.e. do not take any namespaces into account.

If you want to access the attribute from the namespace, you would have to write:. Correspondingly, you can use to access the elements from the namespace preceding the context node. Finally, an example for the namespace axis: selects exactly the namespace node that belongs to the prefix. Incidentally, the qualified name of a namespace node never contains a prefix, see [5.4 Namespace nodes].

As already shown in the examples at the beginning of the chapter, the axis is suitable for filtering out certain element types from a node set within a predicate, e.g. in. Unfortunately, a similar approach does not work for attribute or namespace nodes. This proves to be a hindrance, especially in negative conditions. For example, if you want to select all attributes except for the attribute, you will unfortunately not achieve what you want. This expression still provides all attributes. Since the axis can contain elements, its main node type is therefore the element type, the expression always looks for an element with the name, never for an attribute. One solution to this problem is to evaluate the attribute name, see the functions Surname and local-name.

A QName in the node test is expanded to an expanded name using the namespace declarations from the context of the expression. This is done in the same way as for element names in start and end tags, with the exception that a preset namespace declared with is not used: i.e. if QName does not contain a prefix, the namespace URI is empty (this is the same Rule according to which attribute names are also expanded). It is an error if the QName contains a prefix for which there is no namespace declaration in the context of the expression.

Translator's note:

Qualified names are expanded according to the namespace recommendation [XML Names]. This means in particular that the same prefix does not have to be used in an XPath expression as in the XML document under consideration. It is only important that both prefixes represent the same namespace. For example, if the underlying XML document is an XHTML document, the elements of which belong to the namespace, the document element can be selected via the XPath expression - provided that the prefix was bound to the same namespace in the context of the expression. It is completely irrelevant which prefix was used in the XHTML document - it is even possible that there is only one declaration for the preset namespace:.

In these cases in particular, caution is required. It is very easy to overlook such a namespace declaration, which of course also affects all child elements, and you are willing to only specify the respective element name in an expression, e.g. with the following XSLT statement:. Instead, it would be correct (with a namespace declaration for the sake of completeness):. Accordingly, all steps in localization paths must be fully qualified:.

If you find that XPath expressions no longer return the correct nodes after inserting a DTD into the original document (which is manifested, for example, by the fact that an XSLT stylesheet no longer delivers the expected output), the declaration of a preset namespace is the cause. A declaration within the DTD of the form puts all child elements of without a prefix and also themselves in the XHTML namespace. Without the DTD, they do not belong to any namespace. In such cases, you should include the declaration of the preset namespace in the XML document so that XPath expressions always return the same result regardless of the evaluation of a DTD.

Finally, it should be pointed out once again that a preset namespace in the context of an XPath expression has no effect on the expression. A qualified name without a prefix therefore always addresses an element or an attribute that does not belong to any namespace. The following variant is with it no Alternative to the above example:.

A node test is passed for every node of the main node type. For example, selects all child elements and all attribute nodes of the context node.

Translator's note:

If the context node is an element node, the step only returns the empty node set if it represents the document element. The element node for the document element also has a parent node, namely the root, but this is not of the main node type of the axis, the element type.

A node test can take the form of NCName. In this case the prefix is ​​expanded like a QName using the namespace declarations of the context. It is an error if there is no namespace declaration for the prefix in the context of the expression. The node test is fulfilled for every node of the main node type whose extended name has the namespace URI to which the prefix expands, regardless of the local part of the name.

Translator's note:

For example, selects all descendants from the namespace and all attributes from the namespace.