I’ve read in a technical paper that using XSLT for making amendments in an XML file is a more efficient and preferable way than using the XML Parser like DOM, JDOM, SAX, JSoup etc. So I wanted to know on which parameters XSLT is more efficient and preferable to use than XML parser. (Does XSLT provide more generalized and easier solution?)
Thanking you.
E.g.:
If I’ve one XML file:
<node1>
<node2> TEXT </node2>
</node1>
and I need the output as:
<node1>
<node2> TEXT </node2>
<script src="xyz.js"></srcipt>
</node>
Then either I can write an XSLT for this to get the desired output or I can use XML-parser (DOM, SAX etc.) to write a Java program to insert the required element at the desired place and get the desired output. So for this I have read that XSLT is considered more preferable and effective.
For many small transformations, the cost is dominated by parsing and serialization, and is independent of whether the transformation logic is written in XSLT or Java. (So write it in XSLT, because that is less work).
If the transformation becomes more complex then a smart Java programmer will probably outperform an XSLT engine but an average Java programmer won’t. OK, you know you are smart. But on average, you’re probably average.