sirwittles
sirwittles

Reputation: 25

XSLT / XML select value by name

New to XSLT, but have a scenario below. I am trying to get the GroupControlNumber value of 'ABCDE' in my XSLT, but can't figure out how to call it by name.

Here's a snippet of the XML

<Transactions>
  <Transaction Status="Accepted">
    <IdentifierName>TransactionControlNumber</IdentifierName>
    <TransactionNumber>0001</TransactionNumber>
    <Identifiers>
      <Envelope IdentifierName="ControlNumber" IdentifierValue="12345" />
      <Envelope IdentifierName="GroupControlNumber" IdentifierValue="ABCDE" />
      <Envelope IdentifierName="OriginatorId" IdentifierValue="!@#$%" />
    </Identifiers>
  </Transaction>
</Transactions>

Here's what I got so far on the XSLT side

<xsl:value-of select="../../../../Identifiers/Envelope/@IdentifierValue"/>

But this gives me all three identifier values. I understand why I get all 3, just looking to filter it.

Output
12345 ABCDE !@#$%
Desired output
ABCDE

Thanks!!

Upvotes: 1

Views: 27

Answers (1)

Ed Bangga
Ed Bangga

Reputation: 13006

Here's your xpath.

//Transactions/Transaction/Identifiers/Envelope[@IdentifierName='GroupControlNumber'][1]/@IdentifierValue

Upvotes: 1

Related Questions