cts:element-query( $element-name as xs:QName*, $query as cts:query ) as cts:element-query
Constructs a query that matches elements by name with the content constrained by the query given in the second parameter. Searches for matches in the specified element and all of its descendants. If the query specified in the second parameter includes any element attribute sub-queries, it will search attributes on the specified element and attributes on any descendant elements. See the second example below).
Enabling both the word position and element position indexes
("word position" and "element word position" in the database configuration
screen of the Admin Interface) will speed up query performance for many
queries that use
cts:element-query
. The position indexes
enable MarkLogic Server to eliminate many false-positive results, which can
reduce disk I/O and processing, thereby speeding the performance of many
queries. The amount of benefit will vary depending on your data.
You can query for the existence of an element by specifying an empty
cts:and-query
as
the second parameter. For example, the following will match any instance
of the specified element:
cts:element-query(xs:QName("my-element"), cts:and-query( () ))
cts:search(//module, cts:element-query( xs:QName("function"), "MarkLogic Corporation")) => .. relevance-ordered sequence of 'module' elements ancestors (or self) of elements with QName 'function' and text content containing the phrase 'MarkLogic Corporation'.
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.