对xpath 1.0中两个特定节点的值求和

对xpath 1.0中两个特定节点的值求和,xpath,sum,xpath-1.0,Xpath,Sum,Xpath 1.0,我试图在xpath 1.0中求两个特定值的和。目前,我使用特定的xpath提取我想要的字段,因为我随后将其映射到JSON输出 以下是xml的一个示例: <ns2:Pricing> <ns2:Price> <ns2:ChargeAmount>52247.00</ns2:ChargeAmount> <ns2:PriceDescrip

我试图在xpath 1.0中求两个特定值的和。目前,我使用特定的xpath提取我想要的字段,因为我随后将其映射到JSON输出

以下是xml的一个示例:

<ns2:Pricing>
                  <ns2:Price>
                    <ns2:ChargeAmount>52247.00</ns2:ChargeAmount>
                    <ns2:PriceDescription>act_237</ns2:PriceDescription>
                  </ns2:Price>
                  <ns2:Price>
                    <ns2:ChargeAmount>558.40</ns2:ChargeAmount>
                    <ns2:PriceDescription>adv_261</ns2:PriceDescription>
                  </ns2:Price>
                  <ns2:Price>
                    <ns2:ChargeAmount>45920.80</ns2:ChargeAmount>
                    <ns2:PriceDescription>base_model_invoice_price</ns2:PriceDescription>
                  </ns2:Price>
                  <ns2:Price>
                    <ns2:ChargeAmount>48800.00</ns2:ChargeAmount>
                    <ns2:PriceDescription>base_model_msrp</ns2:PriceDescription>
                  </ns2:Price>
                  <ns2:Price>
                    <ns2:ChargeAmount>1675.20</ns2:ChargeAmount>
                    <ns2:PriceDescription>dealer_holdback</ns2:PriceDescription>
                  </ns2:Price>
                  <ns2:Price>
                    <ns2:ChargeAmount>558.40</ns2:ChargeAmount>
                    <ns2:PriceDescription>dealer_imr_contribution</ns2:PriceDescription>
                  </ns2:Price>
                  <ns2:Price>
                    <ns2:ChargeAmount>3141.64</ns2:ChargeAmount>
                    <ns2:PriceDescription>employee_incentive_amount</ns2:PriceDescription>
                  </ns2:Price>


如何在xpath 1.0中对这两个字段求和?

您可以使用此xpath-1.0表达式来获得和:

/SOAP-ENV:Envelope/SOAP-ENV:Body/ns4:ProcessMessageResponse/ns4:payload/ns4:content/ns2:ShowVehicleInvoice/ns2:ShowVehicleInvoiceDataArea/ns2:VehicleInvoice/ns2:Invoice/ns2:VehicleInvoiceVehicleLineItem/ns2:Pricing/ns2:Price[ns2:PriceDescription='act_237']/ns2:ChargeAmount + /SOAP-ENV:Envelope/SOAP-ENV:Body/ns4:ProcessMessageResponse/ns4:payload/ns4:content/ns2:ShowVehicleInvoice/ns2:ShowVehicleInvoiceDataArea/ns2:VehicleInvoice/ns2:Invoice/ns2:VehicleInvoiceVehicleLineItem/ns2:Pricing/ns2:Price[ns2:PriceDescription='dealer_holdback']/ns2:ChargeAmount

注意名称空间(它们都必须正确定义)。

哇,这太容易了,我本应该想试试。非常感谢。
/SOAP-ENV:Envelope/SOAP-ENV:Body/ns4:ProcessMessageResponse/ns4:payload/ns4:content/ns2:ShowVehicleInvoice/ns2:ShowVehicleInvoiceDataArea/ns2:VehicleInvoice/ns2:Invoice/ns2:VehicleInvoiceVehicleLineItem/ns2:Pricing/ns2:Price/../ns2:Price[ns2:PriceDescription='dealer_holdback']/ns2:ChargeAmount
/SOAP-ENV:Envelope/SOAP-ENV:Body/ns4:ProcessMessageResponse/ns4:payload/ns4:content/ns2:ShowVehicleInvoice/ns2:ShowVehicleInvoiceDataArea/ns2:VehicleInvoice/ns2:Invoice/ns2:VehicleInvoiceVehicleLineItem/ns2:Pricing/ns2:Price[ns2:PriceDescription='act_237']/ns2:ChargeAmount + /SOAP-ENV:Envelope/SOAP-ENV:Body/ns4:ProcessMessageResponse/ns4:payload/ns4:content/ns2:ShowVehicleInvoice/ns2:ShowVehicleInvoiceDataArea/ns2:VehicleInvoice/ns2:Invoice/ns2:VehicleInvoiceVehicleLineItem/ns2:Pricing/ns2:Price[ns2:PriceDescription='dealer_holdback']/ns2:ChargeAmount