JSP+XML newsfeed + querystring + XSLT

I'm new to JSP.  I'm trying to configure a page to transform a remote xml newsfeed with an xsl stylesheet.  I'm using JRun and I find that the custom <jrun:xslt> tag
works well if I can hardcode the newsfeed URI- there seem to be other tag libraries which have very similar syntax.
My problem is, what if the URI contains a variable?

For example in
<jrun:xslt xml="http://PathToNewsfeed" xsl="item.xsl" />
suppose the newsfeed URI is of the form "http://path/newsfeed.xml?id=x" where x is the value of a querystring passed from the referring page.  All the documentation offers is the rather cryptic statement "For improved portability, you also can use a complete URL by specifying a java.net.URL object."

I don't know if this helps, but if I want to do the same in ASP I would use

<%
dim objHTTP,objXML,objXSL
set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "GET", "http://path/newsfeed.xml?id=" & Request("id"), false
objHTTP.send
set objXML = objHTTP.responseXML
set objXSL=Server.CreateObject("MSXML2.DOMDocument")
objXSL.async=false

objXSL.load(Server.MapPath("item.xsl"))

if (objXSL.parseError.errorCode = 0) then
    Response.Write(objXML.transformnode(objXSL))
else
    Response.Write"Error:" & objXSL.parseError.reason & "<br> URL:" & objXSL.url
end if

Set objHTTP = Nothing
Set objXML = Nothing
Set objXSL = Nothing
%>

Many thanks
LVL 1
ParsifalAsked:
Who is Participating?
 
kennethxuConnect With a Mentor Commented:
i'm not sure if jrun tag takes rt-value, but try this:

<%
 String queryString = "?id=x";
 java.net.URL url = new java.net.URL( "http://path/newsfeed.xml" + queryString  );
%>

<jrun:xslt xml="<%=url%>" xsl="item.xsl" />


or this:
<% String queryString = "?id=x"; %>
<jrun:xslt xml='<%="http://path/newsfeed.xml" + queryString%>' xsl="item.xsl" />

0
 
kennethxuCommented:
beware that once you used <jrun> tags, you application can only run on jrun server, it is no long run anywere.

so I would suggest you to try out JSTL's xml processing tags:
http://java.sun.com/products/jsp/jstl/

you can also to write simple java code to to the transfrom. let me know if you have further enquiries.
0
 
kennethxuCommented:
beware that once you used <jrun> tags, you application can only run on jrun server, it is no long run anywere.

so I would suggest you to try out JSTL's xml processing tags:
http://java.sun.com/products/jsp/jstl/

you can also to write simple java code to to the transfrom. let me know if you have further enquiries.
0
 
ParsifalAuthor Commented:
The first example worked once I'd added a request.getParameter statement

String.queryString = request.getParameter("id");

I understand what you're saying about the <jrun:xslt> tag, there seems to be one in the JSTL, <x:transform> which has very similar attributes which I shall try, but right now the jrun library is installed on my machine and JSTL isn't.

Right now I find the concept of "simple Java code" something of an oxymoron, so many thanks.
0
 
kennethxuCommented:
glad to know it works, thanks for the points.
0
All Courses

From novice to tech pro — start learning today.