问题
I use "net.sf.saxon" % "Saxon-HE" % "9.9.1-6" and i'm trying to group some nodes of a HTML Site with XPath.
HTML Page
<div class="item-list">
<div class="row-title"><h3>Item 1</h3></div>
<div class="row-body"><div>nested stuff for Item 1</div></div>
<div class="row-title"><h3>Item 2</h3></div>
<div class="row-body"><div>nested stuff for Item 2</div></div>
<div class="row-title"><h3>Item 3</h3></div>
<div class="row-body"><div>nested stuff for Item 3</div></div>
</div>
Expected result (array)
1. <div class="row-title"><h3>Item 1</h3></div><div class="row-body"><div>nested stuff for Item 1</div></div>
2. <div class="row-title"><h3>Item 2</h3></div><div class="row-body"><div>nested stuff for Item 2</div></div>
3. <div class="row-title"><h3>Item 3</h3></div><div class="row-body"><div>nested stuff for Item 3</div></div>
This is one of my tries/attempts.
//div[contains(@class, 'item-list')]/div[contains(@class, 'row-body') or contains(@class, 'row-title')]
But the result (see below) ist not as expected. (I need the results e.g. 1. and 2. together.)
1. <div class="row-title"><h3>Item 1</h3></div>
2. <div class="row-body"><div>nested stuff for Item 1</div></div>
3. <div class="row-title"><h3>Item 2</h3></div>
4. <div class="row-body"><div>nested stuff for Item 2</div></div>
5. <div class="row-title"><h3>Item 3</h3></div>
6. <div class="row-body"><div>nested stuff for Item 3</div></div>
I also tried something with "following-sibling", but unfortunately without success.
来源:https://stackoverflow.com/questions/62436083/xpath-group-selected-node-with-next-sibling