Help: XSL instead of JSP?

Discussion in 'Java' started by Jed Bartlett, Oct 4, 2004.

  1. Jed Bartlett

    Jed Bartlett Guest

    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>

    If anyone can suggest some ideas and/or links I'd greatly appreciate
    it!

    Jed
     
    Jed Bartlett, Oct 4, 2004
    #1
    1. Advertising

  2. Jed Bartlett

    Sudsy Guest

    Jed Bartlett wrote:
    <snip>

    > 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>
    >
    > If anyone can suggest some ideas and/or links I'd greatly appreciate
    > it!


    Might Tiles (<http://struts.apache.org/userGuide/dev_tiles.html>)
    fill the bill?

    --
    Java/J2EE/UNIX consulting and remote development.
     
    Sudsy, Oct 4, 2004
    #2
    1. Advertising

  3. Jed Bartlett

    Will Hartung Guest

    Re: XSL instead of JSP?

    "Jed Bartlett" <> wrote in message
    news:...
    > 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.


    Methinks you need to ask you employer what the motivation is for moving from
    JSP to XSL, as the two differ rather dramatically.

    XSL can make sense if you're app is publishing a lot of content from
    different sources, but most sites are pretty fixed on what they show and how
    they show it, so why introduce yet another layer of translation into the
    process and complicate it?

    While you could certainly simply replace JSP with XSL wholesale, I think
    that XSL is a bit harder to use. It's certainly harder to learn, IMHO. One
    thing I like about JSPs is that they're written in the same language as your
    servlets, so you don't have to switch hats to use it.

    I'm sure some XSL expert will contradict me on this :)

    Regards,

    Will Hartung
    ()
     
    Will Hartung, Oct 4, 2004
    #3
  4. Jed Bartlett

    Sudsy Guest

    Re: XSL instead of JSP?

    Will Hartung wrote:
    > "Jed Bartlett" <> wrote in message

    <snip>
    > While you could certainly simply replace JSP with XSL wholesale, I think
    > that XSL is a bit harder to use. It's certainly harder to learn, IMHO. One
    > thing I like about JSPs is that they're written in the same language as your
    > servlets, so you don't have to switch hats to use it.
    >
    > I'm sure some XSL expert will contradict me on this :)


    Not me, Will! I think you offered sage advice.

    --
    Java/J2EE/UNIX consulting and remote development.
     
    Sudsy, Oct 4, 2004
    #4
  5. Jed Bartlett

    LX-i Guest

    Jed Bartlett wrote:
    > 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:eek: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:eek: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 ~ ~
    ~ / /\ - | ~ ~
    ~ _____ / \ | ~ 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++++ ~
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    LX-i, Oct 5, 2004
    #5
  6. Jed Bartlett

    Anton Spaans Guest

    Re: XSL instead of JSP?

    "Jed Bartlett" <> wrote in message
    news:...
    > 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>
    >
    > If anyone can suggest some ideas and/or links I'd greatly appreciate
    > it!
    >
    > Jed


    Our company is developing an application that makes extensive use of XSL.
    The choice of XSL has been done for the following reasons:

    1. Our application generates screens that are highly dynamic. There are
    scrollable, sortable, paginateable lists, bread crumbs, complex controls
    with complex data, fairly sophisticated javascript validation, etc.
    2. XSL makes you really think about separating layout from data, which - in
    its 'last' stages - is represented in XML (and our XML data is validated
    implicitly because its structure is generated from XSDs).
    3. Performance is no longer a big issue. You can precompile and cache XSL
    stylesheets (even compile them into Java Classes if you want to).

    Note that we decided upon XSL before Struts and other such JSP technologies
    were mature enough.

    The bible of XSLT is "XSLT 2nd Edition" by Michael Kay (Wrox).

    BTW: your example is incorrect. XSL (& XPath expressions) have quite a steep
    learning curve. XSL is a meta-language without 'side-effects'. It is
    entirely declarative. You define templates (<xsl:template match=...> tags)
    that may match nodes/elements from the input XML-data. In each template you
    can have 'statements' that apply input XML-data to templates
    (<xsl:apply-tempate select=...> tags). The nodes/elements that are selected
    by this xsl:apply-template tag are then matched to all available
    xsl:template tags. The (best) matching xsl:template is then executed for
    each selected node/element. This is a very brief description and you have
    many more xsl-tags.

    Good luck.
    -- Anton.
     
    Anton Spaans, Oct 5, 2004
    #6
  7. Jed Bartlett

    Will Hartung Guest

    Re: XSL instead of JSP?

    "Anton Spaans" <aspaans at(noSPAM) smarttime dot(noSPAM) com> wrote in
    message news:...
    > Our company is developing an application that makes extensive use of XSL.
    > The choice of XSL has been done for the following reasons:
    >
    > 1. Our application generates screens that are highly dynamic. There are
    > scrollable, sortable, paginateable lists, bread crumbs, complex controls
    > with complex data, fairly sophisticated javascript validation, etc.
    > 2. XSL makes you really think about separating layout from data, which -

    in
    > its 'last' stages - is represented in XML (and our XML data is validated
    > implicitly because its structure is generated from XSDs).
    > 3. Performance is no longer a big issue. You can precompile and cache XSL
    > stylesheets (even compile them into Java Classes if you want to).


    Always seemed silly to me to convert internally to XML to convert again to
    HTML. I always considered it for interchanging data between disparate
    systems. Using it for internal communication seems expensive, but that's me.

    > Note that we decided upon XSL before Struts and other such JSP

    technologies
    > were mature enough.


    Really? We've been using Struts et al for over 4 years. In the time we
    upgraded once (long time ago). What part wasn't mature?

    > BTW: your example is incorrect. XSL (& XPath expressions) have quite a

    steep
    > learning curve. XSL is a meta-language without 'side-effects'. It is
    > entirely declarative. You define templates (<xsl:template match=...> tags)
    > that may match nodes/elements from the input XML-data. In each template

    you
    > can have 'statements' that apply input XML-data to templates
    > (<xsl:apply-tempate select=...> tags). The nodes/elements that are

    selected
    > by this xsl:apply-template tag are then matched to all available
    > xsl:template tags. The (best) matching xsl:template is then executed for
    > each selected node/element. This is a very brief description and you have
    > many more xsl-tags.


    That's the other detail with XSL. It makes sense when you finally get deep
    into it, but that first step is a loo-loo.

    Regards,

    Will Hartung
    ()
     
    Will Hartung, Oct 5, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geoff Winsor
    Replies:
    3
    Views:
    6,711
    Ryan Stewart
    Jan 29, 2005
  2. asaguden

    jsf instead of xsl?

    asaguden, Dec 15, 2005, in forum: Java
    Replies:
    0
    Views:
    405
    asaguden
    Dec 15, 2005
  3. Replies:
    1
    Views:
    3,622
    A. Bolmarcich
    May 27, 2005
  4. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help with XSL/XSL:FO for producing revision indicator bar in document.

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Apr 28, 2006, in forum: XML
    Replies:
    6
    Views:
    577
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    May 3, 2006
  5. Replies:
    0
    Views:
    4,419
Loading...

Share This Page