jQuery in Action, 3rd edition
The moose likes XML and Related Technologies and the fly likes basic XSLT question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "basic XSLT question" Watch "basic XSLT question" New topic

basic XSLT question

maya brown
Ranch Hand

Joined: Feb 18, 2009
Posts: 42

I'm confused about what apply-templates does exactly..

these two:

produce exactly the same output.. what exactly does apply-templates do?

thank you..

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 633
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.
vola babu

Joined: Mar 24, 2011
Posts: 6

If you had more than one title and artist tag within cd ...the result would be the same.
I agree. Here's the link: http://aspose.com/file-tools
subject: basic XSLT question
It's not a secret anymore!