I am trying to add another "revision" node to my XML file using xmlstarlet but have not been successful. Here's my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns="http://docbook.org/ns/docbook" xmlns:mw="http://abcxyz.com/namespace/secbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0-variant secbook5.0" status="some_phase">
<title><xi:include href="urn:abcxyz:pn:tm_test.xml"><xi:fallback><!-- fallback for tm_test --></xi:fallback></xi:include>Interface Reference</title>
<info>
<productname>
<xi:include href="urn:abcxyz:pn:tm_test.xml">
<xi:fallback>
<!-- fallback for tm_test -->
</xi:fallback>
</xi:include>
</productname>
<releaseinfo>
<xi:include href="urn:abcxyz:pn:this_release_name.xml">
<xi:fallback>
<!-- fallback for this_release_name -->
</xi:fallback>
</xi:include>
</releaseinfo>
<revhistory>
<revision>
<revnumber>Online</revnumber>
<date>July 2021</date>
<revremark>Version 2.3</revremark>
</revision>
<revision>
<revnumber>Online</revnumber>
<date>Jan 2022</date>
<revremark>Version 2.4</revremark>
</revision>
</revhistory>
<biblioid class="pubsnumber">interface_ref</biblioid>
<subjectset>
<subject>
<subjectterm>SOMETERM</subjectterm>
</subject>
</subjectset>
</info>
</book>
Here's what I have tried so far:
xmlstarlet edit -s /book/info/revhistory --type elem --name revisionTMP --value "" \
-s /book/info/revhistory/revisionTMP --type elem --name revnumber --value "Online" \
-s /book/info/revhistory/revisionTMP --type elem --name date --value "Jul 2022" \
-s /book/info/revhistory/revisionTMP --type elem --name revremark --value "Version 2.5" \
-r /book/info/revhistory/revisionTMP -v revision \
./test_book.xml
While this code works on a simpler XML file like this one where I have been able to successfully add a new "student", it fails on the larger "test_book.xml" file. What am I missing? I am open to other elegant solutions not involving xmlstartlet.
<?xml version="1.0"?>
<Students>
<student>
<name>john</name>
<id>123</id>
</student>
<student>
<name>mike</name>
<id>234</id>
</student>
</Students>
I put the xmlstarlet command in s shell script. The script executes but nothing changes.
xmlstarlet edit -s "//_:revhistory" --type elem --name revisionTMP --value ""\ -s "//_:revhistory/revisionTMP" --type elem --name revnumber --value "Online" \etc. This works. Is my solution robust?