using 'sed' to replace the value in the 1st occurrence of an open/close XML tag with a value that is sum of values from the similar remaining tags



Say my xml looks like the one below. Expectation is that the 1st occurrence of count within header should have a value that equals the sum of values of all the count elements that are present within records. Once the sum is calculated and replaced in the 1st count tag, all the count tags within records should be deleted along with their values. Row occurrences could vary but header only appears once.



<root>
<!-- Header section, occurs only once per document-->
<header>
<count>0</count>
</header>
<!-- Records section, could occur more than once-->
<records>
<!-- Individual records with id and count-->
<Row>
<id>1</id>
<count>10</count>
</Row>
<Row>
<id>2</id>
<count>20</count>
</Row>
</records>
</root>

No comments:

Post a Comment