1

What XPath query should I do to retrieve all property prop_id and prop_name fields where the property contains a field <Field name="prop_label">resource_workskills</Field> In this sample, it should just load:

<Field name="prop_id">100</Field>
<Field name="prop_name">Work Skills</Field>

Sample data:

<?xml version="1.0" encoding="UTF-8"?>
<properties>
  <property>
    <Field name="prop_id">100</Field>
    <Field name="prop_label">resource_workskills</Field>
    <Field name="prop_entity_type">3</Field>
    <Field name="prop_name">Work Skills</Field>
    <Field name="Property ID">100</Field>
    <Field name="Property Language">1</Field>
    <Field name="Text Entry Identifier">0</Field>
  </property>
  <property>
    <Field name="prop_id">101</Field>
    <Field name="prop_label">resource_capacity_categories</Field>
    <Field name="prop_entity_type">3</Field>
    <Field name="prop_name">Capacity Categories</Field>
    <Field name="Property ID">101</Field>
    <Field name="Property Language">1</Field>
    <Field name="Text Entry Identifier">0</Field>
  </property>
</properties>

I do not know how to work with the value of a named field.

Thanks!

Gabriel
  • 5,453
  • 14
  • 63
  • 92

1 Answers1

1

This XPath,

/properties/property[Field[@name="prop_label" and .="resource_workskills"]]
           /Field[@name='prop_id' or @name='prop_name']

will select all Field elements with prop_id or prop_name @name attribute values that are children of a property element that has a child Field element with a prop_label @name attribute value and a string value of "resource_workskills":

<Field name="prop_id">100</Field>
<Field name="prop_name">Work Skills</Field>

as requested.


This is great @kjhughes Thanks! What if I want to use a wildcard in the conditional, such as .="resource_*" so I match all starting by resource_

See: starts-with()

See also: contains() and ends-with()

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • This is great @kjhughes Thanks! What if I want to use a wildcard in the conditional, such as .="resource_*" so I match all starting by resource_ ? – Gabriel Jan 21 '21 at 18:42