If I have a list of similar elements, such that:
<outer-container>
<element attribute="x" />
<element attribute="x" />
.
.
.
<element attribute="y" />
<element attribute="z" />
</outer-container>
How can I wrap the elements with attribute="x" so they are within their own container?
<outer-container>
<inner-container>
<element attribute="x" />
<element attribute="x" />
</inner-container>
.
.
.
</outer-container>
I changed your HTML to make it easier to test.
Assuming you want all of the elements of that kind in one container, positioned where the first one was found, you can do this.
http://jsfiddle.net/5z2uA/4/
If you wanted different consecutive groups to be wrapped together, you can do this.
http://jsfiddle.net/5z2uA/5/