Skip to main content Skip to complementary content

Filtering structure elements

Use the XPath Name property to filter elements in a structure based on an attribute value.

About this task

In this example, you have an XML file containing information about orders. Each order element has a status attribute. You want to configure the structure to only process orders with the status pending.

You could do this by creating a map with a filter on the output loop, but setting a filter in the structure using the XPath Name property can be useful if you want this filter to be automatically applied in all maps that use this structure as input.

You can use the following XML sample:
<orders>
    <order status="pending">
        <orderId>189465984</orderId>
        <customer>
            <lastName>Smith</lastName>
            <firstName>Jane</firstName>
        </customer>
    </order>
    <order status="completed">
        <orderId>189465971</orderId>
        <customer>
            <lastName>Doe</lastName>
            <firstName>John</firstName>
        </customer>
    </order>
    <order status="pending">
        <orderId>189465987</orderId>
        <customer>
            <lastName>Jones</lastName>
            <firstName>Lauren</firstName>
        </customer>
    </order>
</orders>

Procedure

  1. Create an input and an output structure based on the XML sample provided.
    For more information, see Creating a structure from a sample document.
    Information noteTip: You can create one structure, then right-click it and click Duplicate to create the second one.
  2. Open the input structure, click the Read Only drop-down list and select Editable.
  3. Click the order element, scroll down to the XPath Name property and enter order[@status='pending'].
    This indicates that the structure should only read the order elements with the attribute status="pending".
  4. Create a standard map and add your input and output structures.
  5. Drag and drop the input orders element on the corresponding output element to map all the elements.
  6. Click Test Run to see the result.

Results

In this example, the output looks like this:
<orders>
  <order status="pending">
    <orderId>189465984</orderId>
    <customer>
      <lastName>Smith</lastName>
      <firstName>Jane</firstName>
    </customer>
  </order>
  <order status="pending">
    <orderId>189465987</orderId>
    <customer>
      <lastName>Jones</lastName>
      <firstName>Lauren</firstName>
    </customer>
  </order>
</orders>

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!