83397

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?

Answer1:

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...

Answer2:

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>

Answer3:

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"/>

Recommend

  • How to amend the default jqGrid url parameters?
  • Numpy: Finding count of distinct values from associations through binning
  • How to encrypt WebM or MP4 file using ClearKey and then play it
  • jsp how to get base url cleanly without javascript
  • Java ArrayList using in JSTL() [duplicate]
  • How to print a java String in a jsp file [duplicate]
  • Conditional render in tagfile depending on whether the attribute is specified or not
  • Create function that can pass a parameter without making a new component
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • How can we prepend rows to a react native list-view?
  • Extract All Possible Paths from Expression-Tree and evaluate them to hold TRUE
  • XSLT foreach repeating nodes to flat
  • Fail:(TESTMODE) Transactions of this market type cannot be processed on this system
  • List images(01.png) and descriptions(01.txt) from directory
  • Is there a way to do normal logging with EureakLog?
  • D3 nodes and links from JSON with nested arrays of children
  • Alert pop up with LWUIT
  • Get one-time binding to work for ng-if
  • Fetching methods from BroadcastReceiver to update UI
  • How to add date and time under each post in guestbook in google app engine
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Does CUDA 5 support STL or THRUST inside the device code?
  • When should I choose bucket sort over other sorting algorithms?
  • ORA-29908: missing primary invocation for ancillary operator
  • How to delete a row from a dynamic generate table using jquery?
  • using HTMLImports.whenReady not working in chrome
  • How to set the response of a form post action to a iframe source?
  • coudnt use logback because of log4j
  • Change div Background jquery
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Qt: Run a script BEFORE make
  • Authorize attributes not working in MVC 4
  • How can I remove ASP.NET Designer.cs files?
  • Bitwise OR returns boolean when one of operands is nil
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • EntityFramework adding new object to nested object collection
  • sending mail using smtp is too slow
  • reshape alternating columns in less time and using less memory
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs