XPath fiddle
Starting point for xpath query tests
HTML
<html>
<body>
<div id="source">
<em>Source</em>
<div attribute1="aaaa">attribute1="aaaa"</div>
<div attribute1="">attribute1=""</div> <!--This one -->
<div attribute1="bbbb">attribute1="bbbb"</div>
<div>no attributes</div> <!--...and this one -->
</div>
<div>
<button type="button" onclick="applyQuery()">Apply Query</button>
</div>
<div id="target">
<em>Filtered-out divs</em>
</div>
</body>
</html>
CSS
#source {
background: #efe;
}
#target{
background: #fee;
}
JavaScript
window.applyQuery = function(){
var Query = "//div[@id='source']/div[not(@*) or not(string-length(@*))]";
var target = document.evaluate("//div[@id='target']",
document, null, 9, null).singleNodeValue;
var result = document.evaluate(Query, document, null, 6, null);
for(var i=0; i < result.snapshotLength; i++)
{
target.appendChild(result.snapshotItem(i));
}
}