File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

basic XSLT question

 
maya brown
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

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
Posts: 649
3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
Chrome Linux PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you had more than one title and artist tag within cd ...the result would be the same.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic