Search code examples
xsltpositionxslt-2.0xslt-grouping

How to get the first occurrence of value with the matching number from multiple sets


I have request comes with multiple elements where I need the first occurrence of the where data_type="3". Hence there could be multiple values comes as 0,2,3,4 in random.

When I tried to put the below Xpath function it's returning the all values where data_type='3'

<xsl:value-of select="/process/TransactionType/data_xml/transaction/sub_documents/transactionLine[@data_type='3']/Ref"/>

Full input and output code click here code snippet

How I can get the one value instead all values.

Please help me out here.


Solution

  • Well, with XPath if exp gives you a sequence of values and you want the first use e.g. (exp)[1] i.e. (/process/TransactionType/data_xml/transaction/sub_documents/transactionLine[@data_type='3']/Ref)[1].