In Java, from a TransformerFactory
for creating objects to process XSLT, and it has the methods:
newTransformer
which createsTransformer
object, which can transform XML into a result.newTemplates
which createsTemplates
object which can create aTransformer
.
The documentation for Transformer
explicitly states:
A Transformer may be used multiple times.
My application processes various different XMLs with the same XSLT. At the start of the program I use newTransformer
to create a Transformer
then re-use it for all the XMLs (making sure it's synchronized so I only use it from one thread; and calling its reset()
method before each processing.).
That way I don't incur the cost of re-compiling the XSLT for every XML I process.
So what's the point of the newTemplates
and the Templates
object? Should I be using that instead, and creating a new Transformer
object for each XML?