title: Mule Dataweave: using when and Map
body: <p>I have a requirement to retrieve AmountRequired depending on the category from the below input and list out all the repeated elements. </p>
  
  <pre><code>&lt;root&gt;
      &lt;Unspecified&gt;
          &lt;Category&gt;T03&lt;/Category&gt;
          &lt;AmountRequired&gt;993&lt;/AmountRequired&gt;
          &lt;ExcessAmount&gt;250&lt;/ExcessAmount&gt;
          &lt;Currency&gt;GBP&lt;/Currency&gt;
          &lt;ExchangeRate&gt;1&lt;/ExchangeRate&gt;
      &lt;/Unspecified&gt;
      &lt;Unspecified&gt;
          &lt;Category&gt;T03&lt;/Category&gt;
          &lt;AmountRequired&gt;9903&lt;/AmountRequired&gt;
          &lt;ExcessAmount&gt;250&lt;/ExcessAmount&gt;
          &lt;Currency&gt;GBP&lt;/Currency&gt;
          &lt;ExchangeRate&gt;1&lt;/ExchangeRate&gt;
      &lt;/Unspecified&gt;
      &lt;Unspecified&gt;
          &lt;Category&gt;P02&lt;/Category&gt;
          &lt;AmountRequired&gt;992&lt;/AmountRequired&gt;
          &lt;Currency&gt;GBP&lt;/Currency&gt;
          &lt;ExchangeRate&gt;1&lt;/ExchangeRate&gt;
      &lt;/Unspecified&gt;
      &lt;Unspecified&gt;
          &lt;Category&gt;A29&lt;/Category&gt;
          &lt;AmountRequired&gt;929&lt;/AmountRequired&gt;
          &lt;Currency&gt;GBP&lt;/Currency&gt;
          &lt;ExchangeRate&gt;1&lt;/ExchangeRate&gt;
      &lt;/Unspecified&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I want to get the out put as below. When there are 2 tags of T03 its should display both the amounts as below. Also if a Category doesn't exist it doesn't for example P05 and if we have the transformation for it then it errors out that P05 doesn't exist, so is there a way to get over the error even if the input xml doesn't contain the P05 Category?</p>
  
  <pre><code>&lt;amountRequired&gt;
          &lt;amount&gt;929&lt;/amount&gt;
          &lt;currency&gt;GBP&lt;/currency&gt;
          &lt;exchangeRate&gt;1&lt;/exchangeRate&gt;
          &lt;amountInSystemCurrency&gt;550&lt;/amountInSystemCurrency&gt;
      &lt;/amountRequired&gt;
  &lt;amountRequired&gt;
      &lt;amount&gt;993&lt;/amount&gt;
      &lt;currency&gt;&lt;/currency&gt;
      &lt;exchangeRate&gt;&lt;/exchangeRate&gt;
      &lt;amountInSystemCurrency&gt;&lt;/amountInSystemCurrency&gt;
  &lt;/amountRequired&gt;
  &lt;amountRequired&gt;
      &lt;amount&gt;9903&lt;/amount&gt;
      &lt;currency&gt;&lt;/currency&gt;
      &lt;exchangeRate&gt;&lt;/exchangeRate&gt;
      &lt;amountInSystemCurrency&gt;&lt;/amountInSystemCurrency&gt;
  &lt;/amountRequired&gt;
  &lt;amountRequired&gt;
          &lt;amount&gt;992&lt;/amount&gt;
          &lt;currency&gt;&lt;/currency&gt;
          &lt;exchangeRate&gt;&lt;/exchangeRate&gt;
          &lt;amountInSystemCurrency&gt;&lt;/amountInSystemCurrency&gt;
      &lt;/amountRequired&gt;
  </code></pre>
  
  <p>Highly appreciate any help with this</p>