xpathcss-selectorsdeliverance

Preserving order when copying elements using Deliverance / XPath


How would I, using Deliverance & XPath (or CSS) selectors, select and copy list items .one and .three from each list below, but display them in the order of their parent list?

<ul id="a-wrapper">
   <li class="one"></li>
   <li class="two"></li>
   <li class="three"></li>
   <li class="four"></li>
</li>

<ul id="b-wrapper">
   <li class="one"></li>
   <li class="two"></li>
   <li class="three"></li>
   <li class="four"></li>
</ul>

    c,d,e,f,g etc....

The catch is it needs to use a href rule, eg: <prepend href="/blah/deblah" content="#x" theme="#y" />

Using the following just lists all the .one elements, then all the .three elements.

<prepend href="/blah/deblah" content=".one" theme="#y" />
<prepend href="/blah/deblah" content=".three" theme="#y" />

Solution

  • Not sure what you mean, but to grab all at once in source order use this XPATH:

    //ul[@id='a-wrapper' or @id='b-wrapper']/li[@class='one' or @class='three']