JSTL c:import and x:parse inside of x:forEach
Question
I am trying to use the c:import and x:parse tags within an x:forEach.
Is this possible?
If not, what is another way to import multiple xml sources depending on parsed data from another xml source?
<x:forEach select="$sitemap/pages/page" varStatus="status">
<x:set var="location_id" select="@id"/>
<c:import url="xml/pages/page${location_id}.xml" var="location_xml_var"/>
<x:parse var="location_xml" xml="${location_xml_var}" />
<x:out select="$location_xml/pages/page/@name" escapeXml="false"/>
</x:forEach>
This results in a
javax.servlet.jsp.JspException: org.xml.sax.SAXParseException: Content is not allowed in prolog.
error, on the x:parse.
Solution
Seems as though this just won't work.
I ended up looping through the sitemap xml and outputting the ids to a new
<c:set>
variable, then looping through that with
<c:forEach> and <c:import>'ing
each XML file I needed. So the core forEach will allow this, the xml forEach will not.
I realize this is probably the wrong way to go about this problem anyway, but I didn't get any responses to this question yet. Feel free to offer an alternative!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow