I'm trying to use XMLStarlet to transform this (test.xml):
<?xml version="1.0"?>
<root xmlns:doc="http://www.test.com" doc:id="hello">
<a doc:id="x"/>
<a doc:id="x"/>
<c doc:id="x">
<a doc:id="x"/>
<a doc:id="x"/>
<c doc:id="x"/>
</c>
</root>
into this (removing the doc:id attribute on all nodes except c):
<?xml version="1.0"?>
<root xmlns:doc="http://www.test.com" doc:id="hello">
<a/>
<b/>
<c doc:id="hello">
<a/>
<b/>
<c doc:id="hello"/>
</c>
</root>
I've tried this, but it removes all of the doc:id attributes:
xml ed -N doc="http://www.test.com" -d "//@doc:id[not(self::c)]" test.xml