cancel
Showing results for 
Search instead for 
Did you mean: 

Filtering records based on Xpath expression

MohitS
Explorer
0 Kudos
259

Hello Experts,

I am trying to filter records based on the 2 digit country code(ISO_3166-1_Alpha-2_Code). I want to filter the records of workers working in country India(IN). Below is the xml source code.

<wd:Get_Workers_Response xmlns:wd="urn:com.workday/bsvc" wd:version="v32.0">
    <wd:Worker>
        <wd:Employment_Data>
            <wd:Home_Country_Reference>
                <wd:ID wd:type="ISO_3166-1_Alpha-2_Code">AR</wd:ID>
                <wd:ID wd:type="ISO_3166-1_Alpha-3_Code">ARG</wd:ID>
            </wd:Home_Country_Reference>
        </wd:Employment_Data>
        <wd:Personal_Data>
            <wd:Name_Data>
                <wd:First_Name>Rohit</wd:First_Name>
                <wd:Last_Name>Singh</wd:Last_Name>
            </wd:Name_Data>
        </wd:Personal_Data>
    </wd:Worker>
    <wd:Worker>
        <wd:Employment_Data>
            <wd:Home_Country_Reference>
                <wd:ID wd:type="ISO_3166-1_Alpha-2_Code">IN</wd:ID>
                <wd:ID wd:type="ISO_3166-1_Alpha-3_Code">IND</wd:ID>
            </wd:Home_Country_Reference>
        </wd:Employment_Data>
        <wd:Personal_Data>
            <wd:Name_Data>
                <wd:First_Name>Shivam</wd:First_Name>
                <wd:Last_Name>Dubey</wd:Last_Name>
            </wd:Name_Data>
        </wd:Personal_Data>
    </wd:Worker>
</wd:Get_Workers_Response>

I have used below Xpath expression.

//wd:Employment_Data[wd:Home_Country_Reference/wd:ID = 'IN']

which gives me below output

Element='<wd:Employment_Data xmlns:wd="urn:com.workday/bsvc">
	<wd:Home_Country_Reference>
		<wd:ID wd:type="ISO_3166-1_Alpha-2_Code">IN</wd:ID>
		<wd:ID wd:type="ISO_3166-1_Alpha-3_Code">IND</wd:ID>
	</wd:Home_Country_Reference>
</wd:Employment_Data>'

Output of this Xpath expr. doesn't contain Personal_Data node. Is it possible to filter records based on country(IN) and have both nodes (Employment_Data and Personal_Data) in the output by using Xpath expressions?? Or do we have to use XSLT for this transformation.

Expected Output.

<wd:Get_Workers_Response xmlns:wd="urn:com.workday/bsvc" wd:version="v32.0">
    <wd:Employment_Data>
        <wd:Home_Country_Reference>
            <wd:ID wd:type="ISO_3166-1_Alpha-2_Code">IN</wd:ID>
            <wd:ID wd:type="ISO_3166-1_Alpha-3_Code">IND</wd:ID>
        </wd:Home_Country_Reference>
    </wd:Employment_Data>
    <wd:Personal_Data>
        <wd:Name_Data>
            <wd:First_Name>Shivam</wd:First_Name>
            <wd:Last_Name>Dubey</wd:Last_Name>
        </wd:Name_Data>
    </wd:Personal_Data>
</wd:Worker>
</wd:Get_Workers_Response>

Accepted Solutions (0)

Answers (1)

Answers (1)

AdityaMani
Participant
0 Kudos

Hi Mohit,

Try with below-

/wd:Get_Workers_Response [wd:Worker/wd:Employment_Data[wd:Home_Country_Reference/wd:ID = 'IN']]

MohitS
Explorer
0 Kudos

Hi Aditya,

Above expression doesn't filter out the Indian worker records.

Below Xpath expression works as expected while testing it in any online Xpath tester tool.

//wd:Worker[wd:Employment_Data/wd:Home_Country_Reference/wd:ID = 'IN']

However it doesn't work while using in filter step in CPI.

AdityaMani
Participant
0 Kudos

Hi Mohit,

You need to define namespace in Runtine configuration of iflow.