I want to retrieve the data of the next element tag in a document, for example:
I would like to retrieve <blockquote> Content 1 </blockquote> for every different span only.
<html>
<body>
<span id=12341></span>
<blockquote>Content 1</blockquote>
<blockquote>Content 2</blockquote>
<!-- misc html in between including other spans w/ no relative blockquotes-->
<span id=12342></span>
<blockquote>Content 1</blockquote>
<!-- misc html in between including other spans w/ no relative blockquotes-->
<span id=12343></span>
<blockquote>Content 1</blockquote>
<blockquote>Content 2</blockquote>
<blockquote>Content 3</blockquote>
<blockquote>Content 4</blockquote>
<!-- misc html in between including other spans w/ no relative blockquotes-->
<span id=12344></span>
<blockquote>Content 1</blockquote>
<blockquote>Content 2</blockquote>
<blockquote>Content 3</blockquote>
</body>
</html>
Now two things I’m wondering:
1.)How can I write an expression that matches and only outputs a blockquote that’s followed right after a closed element (<span></span>)?
2.)If I wanted, how could I get Content 2, Content 3, etc if I ever have a need to output them in the future while still applying to the rules of the previous question?
Assuming that the provided text is converted to a well-formed XML document (you need to enclose the values of the
idattributes in quotes)Use:
This means in English: Select all
blockquoteelements each of which is the first, immediate following sibling of aspanelement that is a grand-child of the top element of the document.Yes.
You can get all sets of contigious
blockquoteelements following aspan:You can get the contigious set of
blockquoteelements following the (N+1)-stspanby:where
$vNshould be substituted by the number N.Thus, the set of contigious set of
blockquoteelements following the firstspanis selected by:the set of contigious set of
blockquoteelements following the secondspanis selected by:etc. …
See in the XPath Visualizer the nodes selected by the following expression :