Jed said:
I have a web app built with JSP and a controller servlet (all from
scratch, no struts, JSF or anything). I have been asked by my
employer to evaluate XSL as a replacement technology for our JSP web
app.
I looked at a couple simple XSL examples on w3.org that show tables
and stuff and it's impressive. What I need to know is, is it best
practice to replace all my JSP stuff with XSL stuff? For example, my
main.jsp page is a table with cells for header, menu, body, footer --
and body is a <jsp:include> of a variable set by my ControllerServlet
which changes with each command.
Do I replace all this layout stuff with XSL, or would it be smarter to
leave the JSP in place and insert XSL stuff in place of my
<jsp:include>s?
The following is psuedo-code, but can I even do something like this in
XSL?:
<table>
<tr> <xsl:include header.xsl> </tr>
<tr> <xsl:include menu.xsl> </tr>
<tr> <xsl:include context.xsl> </tr>
</table>
That's not quite it. What you'd have is, given XML like...
<myxml>
<mysegment name="segment 1">
<value>Testing</value>
</mysegment>
<mysegment name="segment 2">
<value>More Testing</value>
</mysegment>
</myxml>
....then, you'd have a stylesheet as follows...
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl
utput method="html" />
<xsl:template match="/">
<html>
<head>
<title>Here are the values!</title>
</head>
<body>
<table>
<tr>
<td><b>Segment Name</b></td>
<td><b>Segment Value</b></td>
</tr>
<xsl:apply-templates select="./mysegment" />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="mysegment">
<tr>
<td><xsl:value-of select="@name" /></td>
<td><xsl:value-of select="./value" /></td>
</tr>
</xsl:template>
....what you'll see is that the main part of your page is under the
"template match=/" heading. What the xsl:apply-templates lets you do is
walk through the nodes of your XML file. I'd really, really recommend
the book "Java and XSLT" by Eric M. Burke, published by O'Reilly. (ISBN
0-596-00143-6) He goes into a lot of detail about all the options you
have with XML/XSLT and Java.
For example - notice the <xsl
utput> tag. By changing that, you can
declare the type of output you're generating. You can generate XML,
XHTML, HTML, WML, even plain text - all from the same source data.
Using Java, you run the XML and XSLT through a parser, whose output you
can send wherever it needs to go (to the user from a servlet, to a file,
etc.).
(Note - the above examples are untested...)
If anyone can suggest some ideas and/or links I'd greatly appreciate
it!
(I've got to warn you up front - my ISP has refused several attempts on
my part to get them to configure a mime type for XSLT files - so, if you
can't view them through your browser, just try saving them to your disk
in the same structure, then you should be able to view them locally.)
I use XML/XSLT in a static fashion on my Sunday School's web site.
http://www.knology.net/~mopsmom/daniel/sundayschool is the root URL,
then under there, you'll find the following files...
patrick_requests.xml - this is the most recent prayer request list, in
XML format
patrick_requests.xslt - this is the stylesheet that formats the above
XML into the list I print out each Saturday night to make copies of for
the folks in the mornings
common/formatDate.xslt - this file is used by both the
patrick_requests.xslt and lessons/lesson.xslt to format the date from
the XML
lessons/lesson.xslt - this file is used to format the lesson summaries
each week (it looks for relative path ../common/formatDate.xslt, so if
you're saving them to disk, you'll need to have them like that - that's
just the way I structured it, it's by no means a requirement of XSLT)
lessons/20040704.xml and lessons/20040926etb.xml - these two files are
lesson summary XMLs from different curriculum (illustrates a technique
with variables in lesson.xslt)
Let me know if you have any other questions about what you're seeing.
If it's a "how do ya" about the specific files, you'll find my e-mail
address on my main web site. If it's about the technology in general,
just post it here.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ (e-mail address removed) ~
~ _____ / \ | ~
http://www.knology.net/~mopsmom/daniel ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ I do not read e-mail at the above address ~
~ Please see website if you wish to contact me privately ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~
~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~
~ h---- r+++ z++++ ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~