File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes How Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How "apply-templates" works ?" Watch "How "apply-templates" works ?" New topic

How "apply-templates" works ?

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 386

This above code will print "Hello" as output. But will it also print content of other child elements content and comment ?

If I have following code

Will this code print following
Content directly under page element

My confusion is, when we use apply-templates, does it apply to content directly under element or it applies to content within child element also ? By that I mean, if I have not specified template rule for a child element (eg content element in this case), will apply-templates for parent element (page element in this case) also print content of "content" element ? OR will it just print content directly under it and for child element for which template rule is specified (eg title element in this case) ?

I dont know how to set up XSLT environment locally thats why I am unable to test it. So I am putting question here to understand syntax in xslt.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Here's a book chapter on <xsl:apply-templates>: How XSLT Works.

Here's some more information about the default templates used by XSLT in the absence of <xsl:apply-templates> elements: Default Rules.

And I don't understand what you mean by "set up XSLT environment". There's nothing to be set up, you just have to write code which uses XSLT. Everything you need is built into Java already.

You might want to get yourself a book; it's hard to learn a language by asking questions on forums.
I agree. Here's the link:
subject: How "apply-templates" works ?
jQuery in Action, 3rd edition