Xpath local-name() function to retrieve specific Node element Value

1.4k views Asked by At

My input XML looks like below

    <?xml version="1.0" encoding="UTF-8"?>
<Transaction-315 xmlns="urn:oracle:b2b:X12/V4010/315" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" XDataVersion="2.0" Standard="X12" Version="V4010" CreatedDate="2020-08-19T02:10:41" CreatedBy="XEngine_4016" GUID="{B5D92E00-E1E2-11EA-B316-02001707181F}">
    <Segment-N9>
        <Element-128>AB</Element-128>
        <Element-127>AMAZON</Element-127>
    </Segment-N9>
    <Segment-N9>
        <Element-128>BC</Element-128>
        <Element-127>65036834</Element-127>
    </Segment-N9>
    <Segment-N9>
        <Element-128>CD</Element-128>
        <Element-127>AMAZON200746994</Element-127>
    </Segment-N9>
</Transaction-315>

I want to retrieve always the value 65036834 . From the above sample Element-128 values are always constant . Hence , i tried to retrieve the Segment-N9 node Element-128='BC'/text() using local-name() function.

/*[local-name()='Transaction-315']/Segment-N9[Element-128='BC']/*[local-name()='Element-127']/text()  

But output is not giving the excepted value. Could you please help me some one on this.

1

There are 1 answers

0
Rupesh_Kr On BEST ANSWER

There is namespace in Root element, therefore all child must be call with same namespace or local name

Use this

<xsl:value-of select="*[local-name()='Transaction-315']/*[local-name() = 'Segment-N9'][*[local-name() = 'Element-128']='BC']/*[local-name()='Element-127']/text()"/>

See Transformation at https://xsltfiddle.liberty-development.net/naZYrq6