我正在与另一个XMLStarlet挑战战斗。我现在要做的是用另一个字段值更新一个字段值。在我的情况下,源字段xmlstarlet ed -u "INVOICE/INVOICE_ITEM_LIST/INVOICE_ITEM/QUANTITY" -x "../PRODUCT_FEATURES/FEATURE/FVALUE/text()"
不时存在并且XmlStarlet崩溃。有没有办法避免它并仅在源字段可用时进行复制?
提前感谢您的帮助
<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>
我的示例XML:
update Table1
set VIEW_CD = cmn.VIEW_CD,
VIEW_DETAIL = cmn.VIEW_DETAIL
FROM dbo.Table1 tbl
INNER JOIN dbo.Table2 cmn ON tbl.id = cmn.id
答案 0 :(得分:0)
是的,您可以使用xpath谓词来仅选择那些具有FVALUE的节点:
xmlstarlet ed -u "/INVOICE_ITEM_LIST/INVOICE_ITEM[PRODUCT_FEATURES/FEATURE/FVALUE]/QUANTITY" \
-x "../PRODUCT_FEATURES/FEATURE/FVALUE/text()"
请注意,我已更改路径以适合您的示例XML。