I'm confused about what apply-templates does exactly..
produce exactly the same output.. what exactly does apply-templates do?
Joined: Jan 18, 2011
what exactly does apply-templates do?
xsl:apply-templates element tells the xslt processor to look for templates that match the child nodes and use the most suitable one for each of them that wins out of priority competition to process of them. If there is a select attribute, to look only for those child nodes that are specified in the select attribute.
In the case shown, it is indeed equivalent. But, the xslt document may contain, for various reason such as for processing an ensemble of xml documents with objective. In order not to entangle too much, let's say there are different template matching title element, such as these.
In case the title element that is got matched has id precisely equal to 'xyz', the second template would win out and it would e process differently than other title elements that do not have id attribute or that have id different from "xyz". If you put all these conditionals in place of xsl:apply-templates, it can sometime be done but would be very taxing and rigid in the design in case you want to change tactic. As to which template will win out, it is subject to priority rule... and that bring the subject too far afield.
This is just one illustration and one can imagine more compelling reasons for other situations.