Gemini, your doubt is not stupid at all.
All too often can we do the same things with both DOM/SAX and XSLT. It's not so obvious which technology is preferable: as usual, there are pro and contra for both. Decision depends on 1) what kind of processing we need to apply 3) what are performance requirements 3) which language we are more comfortable with
I think if the task is to present XML document by converting it to HTML or some other format, then it's better to use XSLT. To hardcode presentation information in a program, working with DOM, is also possible, but it's not the best solution. In this case it's much easier to use XSL(T) and we also have advantage of separating data and presentation layers.
If the task is to to transform our XML document, say, to select only specific nodes or re-arrange/sort them, then we again have both options: DOM/SAX or XSLT.
XSLT language was specially designed for XML transformation, and it's often easier to use than Java+DOM+SAX. But in my feeling there are three moments to consider:
1) XSLT doesn't give us as much control on the document as we may want
2) XSLT programs do not scale well. If we can solve our problems with one-page-XSLT, then it's fine. But if we have complicated data and complex processing logic, then our XSLT quickly became unreadable. There are tools for modularity/reuse in XSLT, but in my opinion (which may be wrong!) object-oriented languages fight complexity better.
3) XSLT as a language is different from procedural languages, we used to. It is a functional language and people often find it difficult to understand. For example, we cannot update variables and simple construction I=I+1 doesn't work with XSLT.
This article wil give more information.
Regarding performance requirements, XSLT again doesn't give us too much control, we have to rely on XSLT processor optimization mechanism. (Of course, in typical cases XSLT processor may do a better job than an average programmer
) Most of XSLT processors use DOM to represent an XML tree, so they are not very good for really large documents. There is an exception, however, Saxon, which accepts SAX events as an input.
Bottom line: if you have small XML files without complex processing, XSLT is the best choice. If your files are large, or can become large
then you may consider �real pogramming� with DOM/SAX or at least, choose your XSLT processor more carefully.
I know that Ajith favours DOM/SAX, so I would wait for his reply