Что является противоположностью функции last()
XPath, чтобы выбрать «первый» (очевидно, нет first()
) результат из запроса?
Или как бы мне подражать?
Обновление
Возможно, проблема в моем конкретном примере с использованием предков и контекста.
document.html
<div id="holder" special-header="We have a special header here">
<div class="element" special-header="And this is even more specific">
<p id="interested">Content, content</p>
</div>
</div>
script.php
$doc = new DOMDocument;
$doc->loadHTMLFile('document.html');
$contextNode = $document->getElementById('interested');
/* first try */
$first = $xpath->query('//ancestor::*[@special-header][1]', $contextNode);
echo $first->getAttribute('special-header'); // result == "We have a special header here" intended == "And this is even more specific"
/* second try */
$one = $xpath->query('//ancestor::*[@special-header][last()]', $contextNode); // in case it starts from "first found ancestor" and descends
echo $one->getAttribute('special-header'); // same result as before..
Попытка с position()=1
Я снова получаю тот же результат.