File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes jstl, xslt, and dom Documents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl, xslt, and dom Documents" Watch "jstl, xslt, and dom Documents" New topic
Author

jstl, xslt, and dom Documents

Steve Levin
Greenhorn

Joined: Jul 21, 2006
Posts: 2
Hi,
I'm using struts 1.2.7 and jstl 1.1, I have a org.w3c.dom.Document which I have saved into an httpSession in an action class. Without saving the document in an actual xml file I want to display the document on a jsp page, after doing an xslt transformation. I've been trying to use x:transform but I can't figure out how to manipulate the document without first creating an actual xml file. Any help would be appreciated.

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

The "xml" attribute of the <x:transform> element will accept a Source object, according to the documentation. So a DOMSource based on that Document's root element would work. You could create that along with the Document itself and store it in the session, if you want to avoid scriptlets in your JSP.
Steve Levin
Greenhorn

Joined: Jul 21, 2006
Posts: 2
Thanks for he help but I'm still having some trouble. First off, in the documentation for x:transform, it says that the "xml" attribute has been deprecated and that you should use "doc" instead, but my IDE(Netbeans 5.0) doesn't recognize the "doc" attribute.

Second, and I'm somewhat new to jstl so bear with me, if I don't need to use the doc attribute than how do I access the session scope DOMSource object I created. I thought it was something like this <x:transform var="domSource" scope="session" xslt="/WEB-INF/xml/adjustedGrid.xsl" />, but that doesn't seem to be working either.

Third, I've seen numerous examples online such as

<c:import var="xml" url="aFile.xml" />
<c:import var="xslt" url="transform.xsl" />
<x:transform xml="${xml}" xslt="${xslt}" />

but trying this, I always get the error "According to TLD or attribute directive in tag file, attribute xml does not accept any expression"
and the same error goes for the xslt attribute.

What's going on here?
Thanks again for any help
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

My documentation is for JSTL 1.0. This versioning business is wonderful, isn't it? They had to change the name of one of the main attributes between versions? Pfah.

But your Netbeans likes "xml" and not "doc"? Then it must think that JSTL 1.0 applies. Don't ask me why that might be. And I don't understand the documentation I do have: it says that the "xml" attribute can be a String, but it fails to specify whether that's a string containing the XML or a string containing a URL or a file name. (In the parsers built into Java, it's the latter, but who knows whether JSTL copied that idea.)

Personally I would do this sort of thing in a servlet rather than a JSP. And based on what I've seen while trying to answer the question, my preference is confirmed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jstl, xslt, and dom Documents