• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

basic XSLT question

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..

 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 6
PHP Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you had more than one title and artist tag within cd ...the result would be the same.
 
a wee bit from the empire
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic