XML : Implementing IF with the XMLStarlet Edit function

I'am fighting with the another XMLStarlet challange. What I am trying now is to update one field value with the value of another one. In my case from time to time a source field INVOICE/INVOICE_ITEM_LIST/INVOICE_ITEM/PRODUCT_FEATURES/FEATURE/FVALUE not exist and XmlStarlet crashed. Is there the way to avoid it and copying only if the source field is available?

Thanks in advance for your help

  xmlstarlet ed -u "INVOICE/INVOICE_ITEM_LIST/INVOICE_ITEM/QUANTITY" -x    "../PRODUCT_FEATURES/FEATURE/FVALUE/text()"     

My example XML:

  <INVOICE_ITEM_LIST>    <INVOICE_ITEM>        <PRODUCT_FEATURES/>        <QUANTITY>to_be_set</QUANTITY>     </INVOICE_ITEM>     <INVOICE_ITEM>            <PRODUCT_FEATURES>                 <FEATURE>                        <FNAME>TotalQuantity</FNAME>                        <FVALUE>32.500</FVALUE>                        <FUNIT>MTR</FUNIT>                 </FEATURE>          </PRODUCT_FEATURES>          <QUANTITY>to_be_set</QUANTITY>   </INVOICE_ITEM>  </INVOICE_ITEM_LIST>    

No comments:

Post a Comment