Avoid looping xml in jstl

I would like to do something like this:

<x:out select="$productXML/product/sizes/size[<c:out value='${param.sizeIndex}'/>]" escapeXml="false"/>

but I think the only way to do it is like this:

<x:forEach var="size" begin="${param.sizeIndex}" end="${param.sizeIndex+1}" select="$productXML/product/sizes/*"> <x:out select="$size" escapeXml="false"/> </x:forEach>

Is there a way to do it more like the way I want to?


Not sure what are you trying to solve, but are you sure you need the <c:out value='${param.sizeIndex}'/> inside the '[]' ? JSTL should be processed all at the same time, and you should be able to write something like:

<x:out select="$productXML/product/sizes/size[param.sizeIndex]" escapeXml="false"/>

Or maybe using <c:set var="sIdx" value="${param.sizeIndex}" />

But I'm not totally familiar with JSTL XML tags to be 100% sure...


I think I found what are you looking for here:

<x:set var="abook" select="$applicationScope.booklist/ books/book[@id=$param:bookId]" /> <h2><x:out select="$abook/title"/></h2>


Thanks to GClaramunt [user 98867] putting me on the right tack, I discovered the correct answer:

<x:out select="$productXML/product/sizes/size[$param:sizeIndex]" escapeXml="false"/>

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:Avoid looping xml in jstl