And in XSL template that match <Parent> if I want to apply <Child> template, where <Child> requires parent's id and name, Is it better to pass the parent attribute to child template as PARAMs or have child template access parent's attribute using XPATH. which performs better? Thanks
You can always access a parent node from a child node using a simple XPath expression, whereas explicitly passing the parent as a parameter is clumsy and error-prone. So I would say the XPath version performs better.
posted 13 years ago
Thanks Paul So even if the XML/XSL file considerably complex ( nested nodes), accessing parent attributes using ../../../@xxx (a DOM tree traversal) is efficient than defining a variable x in parent as x = @xxx (Memory allocation, garbage collection)and pass it to the necessary child templates? And does this decision varies in a Transactional process like web page rendering Vs a batch process like document generation?
Also it will be grateful if you could suggest some references/best practises in this area.
[ August 24, 2006: Message edited by: Babji Reddy ] [ August 24, 2006: Message edited by: Babji Reddy ]
One best practice, which I have already alluded to, is to write simple code that can be easily understood rather than more complex code that can easily be broken by careless programming. The short name of this practice is "Premature optimization is evil".
Now if you think that code version A is going to be more "efficient" (whatever you might mean by that) than code version B, then you should try both in your own environment and see. But in the example you gave, I don't see any reason at all to believe there would be any difference in speed or memory utilization between the two options you described.
Originally posted by Paul Clapham: One best practice, which I have already alluded to, is to write simple code that can be easily understood rather than more complex code that can easily be broken by careless programming.
Absolutely. Any time saved in the processing could well be offset by time spent trying to debug problems at a later stage. XSL isn't exactly simple to debug in the first place, so making it simple is a good idea.
Besides, unless the XML file is biiiiiig, the difference in processing speed between either strategy will probably be negligible.
There will be glitches in my transition from being a saloon bar sage to a world statesman. - Tony Banks
posted 13 years ago
I too agree with the priciples of "keeping it simple". May be the example I gave is simple, but the XML does get big ( 40 to 80 KB) and hence options A/B might make difference. And since the time came for prioritizing efficiency over simplicity, I am looking for the opinions/observations of developers who took the approach A/B. And to me the XMLSpy debugger is lot helpful to troubleshoot the XSLT process.
Originally posted by Babji Reddy: the XML does get big ( 40 to 80 KB) and hence options A/B might make difference.
Did you mean 40 to 80 megabytes? That might be considered "big" in some cases. But 40 to 80 KB is trivially small.
But don't let me deter you from doing your own benchmarking. I'm just saying, for small files and for changes (like the one you suggest) that don't look as if they would make any difference, I wouldn't spend any time on that myself. And given the optimizations that XSLT products try to do, I wouldn't try to predict anything in terms of running time or memory usage.
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad: