mulemule-elxpath-3.0

MEL XPath3 expression for attribute


I am splitting an xml document and below is a sample

<Row>
    <tags id="1165" name="Code_Name">pqr</tags>
    <tags id="1102" name="Source_Name">xxx</tags>
    <tags id="1176" name="Code_Value">12_M</tags>
    <tags id="1177" name="Code_Value_Description">Annual</tags>
    <tags id="1148" name="System_Control">R</tags>
    <tagi id="1169" name="Code_Instance">10278</tagi>
    <tags id="10494" name="Has_History"/>
    <tags id="10495" name="Obsolete"/>
    <tagi id="1179" name="Code_Value_Instance">1545</tagi>
    <tagi id="1168" name="Source_Number">4</tagi>
    <tags id="1106" name="Update_Date">20150821</tags>
    <tags id="944" name="Update_Source">abc</tags>
</Row>

I need to extract the value of id 1165. I am trying a MEL XPath3 expression and getting errors.

#[xpath3('/Row/tags/@id='1165'')]

I know #[xpath3('/Row/tags[1]')] works but I need select based on the attribute id. Fragment of the flow is below.

        <foreach collection="xpath3('/soapenv:Envelope/soapenv:Body/cmn:Response/Report/Level/Tab/*', payload, 'NODESET')" doc:name="For Each">
            <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
            <logger message="PL3  #[xpath3('/Row/tags/@id='1165'')] #[xpath3('/Row/tags[1]')]" level="INFO" doc:name="Logger"/>
</foreach>

Any help would be greatly appreciated.

Regards, Hari


Solution

  • xpath3 is namespace-aware so you need to provide that. But you can use wildcard as below. In addition, you need to escape the single quotes.

    xpath3('/*:Row/*:tags[@id=\'1165\']')