Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on apply template

 
Dhiren Joshi
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!