I am new in XSLT and I started to support an application which has the servlet below. Could someone help me to understand which are the patterns in this servlet related to XSLT? Beyond the basic methods get and post, I didn't understand the purpose of too many methods. Obviously I can debug but I can figure out every purpose because it is not clean code: at least when I compare with much more straight forward servlets that I have supported. It seems that who has developed this application has used some common practice of wrapping DOM and SAX methods in the servlet. I have read a lot in the last days about how XSLT works and have saw some examples about its advantage of converting xml in html. Basically, any comment or critic will help to figure out what is the advantage of such approach and understand better about common practice related to XSLT paradigms.
I have to say that asking people to explain nearly 800 lines of code to you is a bit excessive. I doubt that anybody wants to go through that code and spend half an hour or so documenting it and probably failing to help you understand it anyway. So could you ask a more specific question? You aren't going to understand this complex piece of code all at once anyway, so why not pick some method and ask about that?
Paul thank you for your suggestion. An specific question could be "what is a good approach to use Xalan (XSLT) and Xerces (XML Parser) in a servlet which is used to answer back every event from user by reading templates (XSL) and data stored in XML files". I am used to work with JSF and Strut II (MVC Pattern) and suddenly I start to support a small but very important application designed to receive, process and return XML's and every persistent data is recorded in XML (there isn't database at all). Based in my experience this is a bad practice but I might be judging wrongly because I am addicted to store data in relational database and I have never used XSLT to read a XSL and render the HTML to client. I have used XPath but I never saw a web site reading too many tags in a couple of XML and XSL only to send a HTML to browser after a simple click in menu. In this application, basicly there is only 1 jsp and 1 servlet and more than 10 XSL which are related to each web page. I mentioned my background only to clarify my doubt: my focus is "is the attached code a good practice?" and "what could be a well-know recommended pattern for use XSLT + XML + XSL without database?"
Well, there's certainly a lot of criticism that one could direct at the code you posted, but then it is 800 lines long. And that criticism wouldn't be directed at the extremely high-level architectural issues that you seem to be interested in, but rather at detailed things like the writer apparently didn't know how to use the File class properly, things like that.
I once designed and implemented a website in which the pages were HTML output from XSL transformations, but I used relational databases as the input and SAX event streams as input to the XSLT, so I'm certainly not going to say it's bad practice to do that. As for your questions about patterns, it's hard for me to tell what you're getting at there, or more importantly why you want to know.
I should also mention this: back in the early days of web applications, people would just write a bunch of servlets which would output HTML. Before long it became apparent that some architectural design would be helpful, so the MVC (Model, View, Controller) architecture was applied. At that time (which I believe was about 2004 give or take a few years) there were a couple of options suggested. One of the options was using XSLT to generate the HTML, and another option was to write JSPs to generate the HTML. Apparently I wasn't the only one who tried out the XSLT idea; however the JSP idea pretty much swept the field and the XSLT idea was quietly dropped.
This doesn't mean that using XSLT was a bad practice, though, it means it wasn't a popular practice. And popularity is very important in the software business.
Paul, supposing I have the opportunity to develop today an application from the scratch with this requirements: (1) it will have a very small front-end - 20 web pages, (2) it will receive a lot of xmls to be processed and generates xmls as return, (3) there will be a scheduler which evokes every each five minutes the thread to process the files which are located in some folder. Based in my experience, at first thinking, it sounds useful consider to use XSLT 3.0/XPATH/XSD to read/parse/validate the xml and generates the xml to return but It sounds very useless expend energy for considering XSLT v3.0/XSL to render HTML to Browser for the 20 web pages. As I said, based in my experience, I would consider any MVC framework but I wouldn't give a small chance to XSLT for generating HTML to client. So my final question is: is there an advantage to use XSLT 3 instead of traditional MVC framework? Is there performance, scalability, secury or any other advantage for considering XSLT a better option? Please, ignore the learning difficulty for my scenario.
Yup, yup, yup. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss