maandag 11 juni 2007

Content is not allowed in prolog

This one is rather tricky, while transforming xml with xslt with this jstl:
transform.jsp

<%@ page session="false" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<x:transform xslt="question.xsl">
<c:import url="questions.jspx" />
</x:transform>


I've got this error:

javax.xml.transform.TransformerException:
org.xml.sax.SAXParseException: Content is not allowed in prolog."


The solution is to specify the xsl-file in a variable:

<%@ page session="false" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<<@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<c:import url="question.xsl" var="xslfile"/>
<x:transform xslt="${xslfile}">
<c:import url="questions.jspx" />
</x:transform>

Geen opmerkingen: