Can I create a JSP from dynamically generated XML?

I want to create a JSP using XSLT tags and <x:transform> . But I donโ€™t have an XML file in my file system and I canโ€™t import it like: <c:import url="./xml/MyXml.xml" var="xmldoc"/> . It is generated dynamically in Java code and is set as the String attribute for the request. I am trying to do it like this:

 <div id="mydiv"> <c:set var="xmldoc"> <c:out value="${requestScope.someXmlString}"/> </c:set> <c:import url="./xsl/MyStylesheet.xsl" var="xsltdoc"/> <x:transform xml="${xmldoc}" xslt="${xsltdoc}"/> </div> 

or

 <div id="mydiv"> <c:set var="xmldoc" value="${requestScope.someXmlString}"> <c:import url="./xsl/MyStylesheet.xsl" var="xsltdoc"/> <x:transform xml="${xmldoc}" xslt="${xsltdoc}"/> </div> 

But it does not work. It seems that <x:transform> expects only an XML document (not a string). How can I do it? Or is there another way to do this?

+6
source share
1 answer

You do not need to try to set a value that you could directly refer to the request value in the <x:transform> .

 <x:transform xml="${requestScope.someXmlString}" xslt="${xsltdoc}"/> 

By default, jstl uses the request scope. Therefore, if you set a value like request.setAttribute ("someXmlString", xmlStr); then you can directly call

 <x:transform xml="${someXmlString}" xslt="${xsltdoc}"/> 

Both should work.

0
source

All Articles