I want to sort xml elements numerically, but failed at the last step(to merge two xml).
This is what I have tried:
content of xml file
$ cat input.xml
<root>
<title>hello, world</title>
<items>
<item>2</item>
<item>1</item>
<item>3</item>
</items>
</root>
sort items
$ xmlstarlet sel -R -t -m '//item' -s A:N:- 'number(.)' -c '.' -n input.xml
<xsl-select>
<item>1</item>
<item>2</item>
<item>3</item>
</xsl-select>
delete items
$ xmlstarlet ed -d '//item' input.xml
<?xml version="1.0"?>
<root>
<title>hello, world</title>
<items/>
</root>
how to merge the outputs? the result should be:
<root>
<title>hello, world</title>
<items>
<item>1</item>
<item>2</item>
<item>3</item>
</items>
</root>