find all the sibling xml element based on a condition on another sibling in javascript

  find, javascript, jquery, sum, xml

How to get all the Quantity element sum for which PLU value falls under variable plus. So Quantity should be 4 in javascript

var plus = '31101,31102,31103,31104,31105,31106,31107,31118,31119,31110,31111,31112,31113,31114'.split(",");

 var xml = '<Items><Item><PLU>31101</PLU><Quantity>1</Quantity><Amount>120</Amount><UnitPrice>120</UnitPrice></Item><Item><PLU>31102</PLU><Quantity>1</Quantity><Amount>260</Amount><UnitPrice>260</UnitPrice></Item><Item><PLU>31106</PLU><Quantity>1</Quantity><Amount>60</Amount><UnitPrice>60</UnitPrice></Item><Item><PLU>31105</PLU><Quantity>1</Quantity><Amount>0.01</Amount><UnitPrice>0.01</UnitPrice></Item><Item><PLU>311</PLU><Quantity>10</Quantity><Amount>17.5</Amount><UnitPrice>2.25</UnitPrice><PriceAdjustment PriceAdjustmentID="12345678"><Amount>-1</Amount><Quantity>2</Quantity><Reason>Buy 2 Get 20% Off</Reason></PriceAdjustment><PriceAdjustment PriceAdjustmentID="12345678"><Amount>-1</Amount><Quantity>2</Quantity><Reason>Buy 2 Get 20% Off</Reason></PriceAdjustment><PriceAdjustment PriceAdjustmentID="12345678"><Amount>-1</Amount><Quantity>2</Quantity><Reason>Buy 2 Get 20% Off</Reason></PriceAdjustment><PriceAdjustment PriceAdjustmentID="12345678"><Amount>-1</Amount><Quantity>2</Quantity><Reason>Buy 2 Get 20% Off</Reason></PriceAdjustment><PriceAdjustment PriceAdjustmentID="12345678"><Amount>-1</Amount><Quantity>2</Quantity><Reason>Buy 2 Get 20% Off</Reason></PriceAdjustment></Item></Items>';```

Source: Ask Javascript Questions

LEAVE A COMMENT