1

I am using Kettle and the Get Data From XML transformation to extract certain information from an XML file. I set Loop Xpath to /*[name()='feed']/*[name()='entry'] which brings in all the relevant fields.

I would like to extract each <region> node from the regions node as its own field so that I can later concatenate them with a "/" delimiter.

Next, I need to create fields like weekly_rate_from and weekly_rate_to for each <rate> node. I can't quite figure out the Xpath to differentiate between attributes like periodType and then also extracting the from and to information as well. In other words, I need to extract only "to" and "from" rate attributes when periodType=weekly

Hopefully this isn't too confusing I'm probably not explaining well

<feed>
<entry>
  <content>
    <listing>    
      <regions>
        <region>World</region>
        <region>USA</region>
        <region>California</region>
        <region>Inland Empire California</region>
        <region>Temecula Valley</region>
        <region>Temecula</region>
      </regions>
      <rates rentalBasis="property">
        <rate from="3395" to="4175" currencyUnit="USD" periodType="weekly"/>
        <rate from="599" to="749" currencyUnit="USD" periodType="nightly-weekday"/>
        <rate from="799" to="1019" currencyUnit="USD" periodType="nightly-weekend"/>
      </rates>
    </listing>
  </content>
</entry>
<entry>
...
</entry>
... for a total of 20 "entry" nodes
</feed>
Jake Parker
  • 13
  • 1
  • 4

1 Answers1

2

Counting all region elements:

count(/feed/entry/content/listing/regions/region)

Retrieve the from and to for only periodType weekly:

/feed/entry/content/listing/rates/rate[@periodType = 'weekly']/@from
/feed/entry/content/listing/rates/rate[@periodType = 'weekly']/@to
Mark Veenstra
  • 4,691
  • 6
  • 35
  • 66