1
votes

I wants to give dynamic value for select attribute in JSTL XML

I have the following code

<x:forEach var="product" begin="${startRange}" end="${endRange}" select="$doc/queryProductResponse/product">
 <c:set var="nameElement" value="name"/>
 <tr class="tableRow">
          <td>
            <x:out select="$product/[nameElement]" />
          </td>
  </tr>

Here i am reading product xml and i wants to find the element values dynamically.So whatever the element i wants to get it is stored in a variable.So in the above code i stored the element name in a variable called nameElement,and i am trying to pass to the select attribute of the x:out tag. But it is not working.Is there anyway to specify the element name dynamically using JSTL?

1

1 Answers

0
votes

I got the answer . Using XPath name function we can specify the attribute name dynamically.

<c:set var="elementName" value="description"/> 
<x:out select="$product/*[name()=$elementName]" />