I have this XML with multiple products and I want to add a new element with the values of other elements. I want to add a new element to each titled . This should include the values of ProductOption, PurchaseOption, Quantity. Example should look like <sku>price-each-an-order-250-499</sku>
.
I am open to different technologies, like command line sed, bash etc.., php, python, javascript.
Input XML
<Catalog>
<Product>
<Number>82508</Number>
<Title>Product Title</Title>
<Description>description</Description>
<Variations>
<!-- An Order; no imprint -->
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>250-499</Quantity>
<MinQuantity>250</MinQuantity>
<MaxQuantity>499</MaxQuantity>
<Price>1.09</Price>
</Variation>
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>500-999</Quantity>
<MinQuantity>500</MinQuantity>
<MaxQuantity>999</MaxQuantity>
<Price>0.95</Price>
</Variation>
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>1000-2499</Quantity>
<MinQuantity>1000</MinQuantity>
<MaxQuantity>2499</MaxQuantity>
<Price>0.93</Price>
</Variation>
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>2500-4999</Quantity>
<MinQuantity>2500</MinQuantity>
<MaxQuantity>4999</MaxQuantity>
<Price>0.87</Price>
</Variation>
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>5000</Quantity>
<MinQuantity>5000</MinQuantity>
<MaxQuantity></MaxQuantity>
<Price>0.84</Price>
</Variation>
<!-- A Quote; no imprint -->
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>A Quote</PurchaseOption>
<Quantity></Quantity>
<MinQuantity></MinQuantity>
<MaxQuantity></MaxQuantity>
<Price>0.00</Price>
</Variation>
<!-- A Sample; no imprint -->
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>A Sample</PurchaseOption>
<Quantity>1</Quantity>
<MinQuantity>1</MinQuantity>
<MaxQuantity>1</MaxQuantity>
<Price>0.00</Price>
</Variation>
</Variations>
</Product>
</Catalog>
Expected Output
<Catalog>
<Product>
<Number>82508</Number>
<Title>Product Title</Title>
<Description>description</Description>
<Variations>
<!-- An Order; no imprint -->
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>250-499</Quantity>
<MinQuantity>250</MinQuantity>
<MaxQuantity>499</MaxQuantity>
<Price>1.09</Price>
<Sku>price-each-an-order-250-499</sku>
</Variation>
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>500-999</Quantity>
<MinQuantity>500</MinQuantity>
<MaxQuantity>999</MaxQuantity>
<Price>0.95</Price>
<Sku>price-each-an-order-500-999</sku>
</Variation>
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>1000-2499</Quantity>
<MinQuantity>1000</MinQuantity>
<MaxQuantity>2499</MaxQuantity>
<Price>0.93</Price>
<Sku>price-each-an-order-1000-2499</sku>
</Variation>
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>2500-4999</Quantity>
<MinQuantity>2500</MinQuantity>
<MaxQuantity>4999</MaxQuantity>
<Price>0.87</Price>
<Sku>price-each-an-order-2500-4999</sku>
</Variation>
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>An Order</PurchaseOption>
<Quantity>5000</Quantity>
<MinQuantity>5000</MinQuantity>
<MaxQuantity></MaxQuantity>
<Price>0.84</Price>
<Sku>price-each-an-order-5000</sku>
</Variation>
<!-- A Quote; no imprint -->
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>A Quote</PurchaseOption>
<Quantity></Quantity>
<MinQuantity></MinQuantity>
<MaxQuantity></MaxQuantity>
<Price>0.00</Price>
<Sku>price-each-a-quote</sku>
</Variation>
<!-- A Sample; no imprint -->
<Variation>
<ProductOption>Price Each</ProductOption>
<PurchaseOption>A Sample</PurchaseOption>
<Quantity>1</Quantity>
<MinQuantity>1</MinQuantity>
<MaxQuantity>1</MaxQuantity>
<Price>0.00</Price>
<Sku>price-each-a-sample-1</sku>
</Variation>
</Variations>
</Product>
</Catalog>
Not sure what to use to accomplish this. Any examples or tutorials would be helpful.