KK99
KK99

Reputation: 1989

Question on XSLT following-sibling

My XML structure looks like this

<COMPANY>
<COMPANY-DATA>ABC</COMPANY-DATA>
<ID>10800</ISSUE-ID>
<PROJECT-ID/>
</COMPANY-ISSUE-INFO>
 </COMPANY>
"COMPANY Node repeats"

What I want to do is I want to do I want to check for COMPANY-DATA='ABC' and get its ID

I tried using

<xsl:value-of select="//COMPANY-DATA/.='ABC'/following-sibling::ID/."/> 

But this doesn't seem to work and throwing error

Expression must evaluate to node-set //COMPANY-DATA/.= -->'ABC'<-- /following-sibling::ID/.

Thanks,

Karthik

Edit: I found the solution

 **<xsl:value-of select="//COMPANY-DATA[.='ABC']/following-sibling::ID/."/>** 

Thanks

Upvotes: 0

Views: 1653

Answers (2)

KK99
KK99

Reputation: 1989

<xsl:value-of select="//COMPANY-DATA[.='ABC']/following-sibling::ID/."/>

Upvotes: 1

Chris
Chris

Reputation: 7855

The first thing i noticed ist, that whe snipped you postet is no valid XML. The Element <ID> is closed by the End-Element </ISSUED_ID> and there is a single closing Element </COMPANY-ISSUE-INFO>

But if i get you right, you want to find the ID of the <COMPANY> Element where the <COMPANY-DATA> is ABC. So your Comment on your question should do this. But you could also use

<xsl:value-of select="//COMPANY[COMPANY-DATA='ABC']/ID"/>

This removes the need of having the Comapny-Data and ID in a specific sequence.

Upvotes: 1

Related Questions