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 Generic question on <xsl:apply-templates> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Generic question on <xsl:apply-templates>" Watch "Generic question on <xsl:apply-templates>" New topic

Generic question on <xsl:apply-templates>

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 543

Hello All,

I actually have two questions related to XSLT.

1) What is the purpose, meaning and usage of <xsl:template match="*"/>

2) When we say <xsl:apply-templates select="SomeName"/> (Here somename is really some randam name), what is actually happening ?

For my second question, I believe "SomeName" could be really some XPath expression. Is that correct?

So for example, if my syntax is like

Does the above syntax means to have the template applied to all the elements "Author"s under "Book"s in my source XML? If yes, what template is being applied here and where do we specify that.

To be more clear, if my XML is like

Now if I want to have my new transformed XML to highlight only Authors ignoring the rest of the elements with a red font,

Is my XSL correct?

What would happen, if I just say

Please advice.


Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 543

Just to add more information,

Now my XSL is like this

Now when I tried to debug the transformation using Oxygen tool (XML Editor tool), I had set the breakpoint at <xsl:apply-templates select="businessinfo/businessline"/>

and I see that the control has immediately gone to <xsl:template match="businessline"> and the entire section of XML under businessline element in source XML has been selected, indicating that part of XML is being processed now. My question here is, why did control go to <xsl:template match="businessline">. I have not specified this in XSL. But why did it go?

Also, after this, when the execution reached <xsl:apply-templates select="businessinfo/errors"/>, the debugger took the control to

and nothing has been processed.

Please be advised that, there is exactly a similar version running in production in our project.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 543

Any advice on this.
It is sorta covered in the JavaRanch Style Guide.
subject: Generic question on <xsl:apply-templates>
It's not a secret anymore!