?
Solved

JSP+XML newsfeed + querystring + XSLT

Posted on 2003-02-26
5
Medium Priority
?
318 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:Parsifal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 200 total points
ID: 8029499
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8029521
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8029530
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
 
LVL 1

Author Comment

by:Parsifal
ID: 8030493
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8030647
glad to know it works, thanks for the points.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question