wood burning stoves 2.0*
The moose likes Product and Other Certifications and the fly likes Question on apply template 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 » Certification » Product and Other Certifications
Bookmark "Question on apply template" Watch "Question on apply template" New topic
Author

Question on apply template

Dhiren Joshi
Ranch Hand

Joined: Dec 09, 2003
Posts: 463
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
<xsl:apply-templates/ >
</xsl:template>

<xsl:template match="/test">
<xsl:apply-templates/ >
</xsl:template>

<xsl:template match="AAA">
<DIV style="color urple">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
</xsl:stylesheet>
<xsl:template match="CCC">
<DIV style="color urple">
<xsl:value-of select="name()"/>
<xsl:text> id=</xsl:text>
<xsl:value-of select="@id"/>
</DIV>
</xsl:template>
</xsl:stylesheet>

XML

<?xml version="1.0"?>
<test>

<AAA id='a1' pos='start'>
<BBB id='b1' />
<BBB id='b2' />
</AAA>
<AAA id='a2'>
<BBB id='b3' />
<BBB id='b4' />
<CCC id='c1'>
<DDD id='d1' />
</CCC>
<BBB id='b5'>
<CCC id='c2' />
</BBB>
</AAA>
</test>

a. output will not print CCC attributes
b. Output will only print AAA id
c. Both a and b are correct
d. BBB will be printed.

Please explain ..the anwser. Single select answer

Thanks
Dhiren
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Dhiren, since you seem to be posting a lot of XML snippets it would be a good thing to use the [CODE][/CODE] UBB tag and check the "Disable smilies in this post" checkbox in the "Options" section of the "Post A Reply/Add New Topic" view.

It would help people to read the snippets you post and thus improve your chances of getting answers...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on apply template
 
Similar Threads
following::* doubt
Another question on XSL
accessing Attribute values of element.
Difference between count() and last()
A doubt about Xpath expression