This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

Generic question on <xsl:apply-templates>

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

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.


Regards
KumarRaja

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

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: 518
    
    2

Any advice on this.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Generic question on <xsl:apply-templates>
 
Similar Threads
xsl processing
Using XSL to display XML
XSL fails with xmlns
Why aren't DENSITY & DISTANCE text displayed?
what is template rule in xsl ?