How to get a child node of a particular parent node in XSLT?

24 Views Asked by At

I have an input something like this:

<applicationData>
<product>
 <productCode>ABC</productCode>
 <actionType>NW</actionType>
 <product>
  <productCode>66890</productCode>
  <actionType>NW</actionType>
   <product>
    <productCode>66889</productCode>
    <actionType>NW</actionType>
   </product>
    <product>
    <productCode>66566</productCode>
    <actionType>NW</actionType>
   </product>
 </product>
</product>
</applicationData>
<applicationData>
 <product>
  <productCode>66813</productCode>
  <actionType>NC</actionType>
   <product>
    <productCode>66788</productCode>
    <actionType>RM</actionType>
   </product>
 </product>
</applicationData>

Each applicationData has different levels of product. How do i get all the productcodes of the last level of product?

The first applicationData is having 3 levels of product whereas, the second one is having 2 levels.

For example, i would need to check if productCode = 66889 and productCode=66566 . How do i achieve this in XSLT ? what would be the XPath ?

I tried something like this :

applicationData/product[..//productCode='66889' and ..//productCode='66566']

But doesnt help. Please help.

1

There are 1 best solutions below

0
y.arazim On

How do i get all the productcodes of the last level of product?

If by "last level of product"" you mean a product that does not have a child product, you would be looking for:

//product[not(product)]/productCode

See the demo here.