Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select list in jhtml

Status
Not open for further replies.

kristolcrawley

Programmer
Jun 17, 2002
19
US
I have a jhtml page that I'm currently doing a db call to fill a select list. I'd like to use xml to do this instead. I created an xml with the output for the select list but I can't figure out how to get the jhtml to read the xml. I can get it to generate the "name" element in a table, but not for a select list. I can't put the jhtml into an xsl and render it, it has to be xml/xsl read from the jhtml.

affiliate.xml
<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;affiliate.xsl&quot;?>
<affiliate>
<detail>
<name>NORTEL</name>
</detail>
<detail>
<name>TRANSPORTATION</name>
</detail>
<detail>
<name>BCI</name>
</detail>
<detail>
<name>SOLECTRON</name>
</detail>
<detail>
<name>BMW</name>
</detail>
<detail>
<name>MEDICIS</name>
</detail>
<detail>
<name>FUJI</name>
</detail>
<detail>
<name>SUN MICROSYSTEMS</name>
</detail>
</affiliate>
 
Wow, what server are you using? I had to look JHTML up to find out what it is. JSP has been around for like 4 years why are you using JHTML?

Your post taken in whole is confusing to me but in parts like this:

>> currently doing a db call to fill a select list.

So you want to generate an HTML <select> element with the rows returned from a SQL query?

>> I'd like to use xml to do this instead.

So you want the datasource to be an existing XML document rather than a resultset from a SQL query?

>> I created an xml with the output for the select list

How did you do that? What is the result of it? You have the XML file on disk now?

>> I can't figure out how to get the jhtml to read the xml.

You use a XML parser to do that. You can either build a DOM Document object or use a SAX Parser and handle the events. There are tutorials about this at java.sun.com.

>> I can get it to generate the &quot;name&quot; element in a table, but not for a select list.

No idea what that means

>> I can't put the jhtml into an xsl and render it

Right. XSL(T) only processes well formed XML.

>> it has to be xml/xsl read from the jhtml.

You can’t read from jhtml. Jhtml or JSP, produces an output stream that is sent back to the browser. The JSP code is just a text file that is compiled into a Java Servlet class and is executed at runtime therefore you could read the source code of the JSP technically but that would not accomplish anything. You can capture or intercept the stream produced by the JSP but that seems the long way around to accomplish your goal.

It is possible that your goal fits this very common model:
(*) Query a database and obtain a result set
(*) or the database can natively return an XML document
(*) Create a DOM Document and build a XML document using the result set
(*) Create a DOM Document from a XSL(T) text source ( this could be a database entry again or a disk file or a Web Service etc. )
(*) Use the DOM transformation feature to transform the XML into HTML using with the XSL(T)
(*) Stream the result back to the browser

I believe you will find examples of all that even using the MVC pattern and possibly the Struts Framework at one or both of java.sun.com / apache.org


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top