• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock exam question

 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What is the output of the code below?
-------------XML document-------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="MyTest.xsl"?>
<test:MyNode xmlns:test="http://www.whizlabs.com">
<test:foo>Some Element Text</test:foo>
</test:MyNode>
-------------XSL document------------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" version="1.0"
xmlns:whiz="http://www.whizlabs.com">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="whiz:MyNode">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="whiz:foo">
<h1>FOUND</h1>
</xsl:template>
</xsl:stylesheet>

The answer is:
"<h1>FOUND</h1>" is inserted into the new XML document.
I am wondering why the above, not just "FOUND", <h1> tag will be rendered here, right?
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are viewing this in an IE browser, this will surely be rendered and a bold FOUND will be seen; I think it depends on where you see it; The bottom line is that xlst transform just delivers the format mentioned by us in the template and it is left upto the interpretation of the application for presenting the output; That is why xslt is very powerful and can give us practically output in anyway we want provided we know the intended output format;
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Then <html>, <body> tags should also be inserted in the output, right?
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes; The total output looks something like below -
<html xmlns:whiz="http://www.whizlabs.com">
<body>
<h1>FOUND</h1>
</body>
</html>
I have one more concern here; Whey is the xmlns:whiz attribute being added to the <html> element??
I tried having some other namespace declaration as xmlns:jaya="www.jaya.com" and i can see this also added in the attribute list for the <html> output element
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jayadev Pulaparty:
Yes; The total output looks something like below -
<html xmlns:whiz="http://www.whizlabs.com">
<body>
<h1>FOUND</h1>
</body>
</html>
I have one more concern here; Whey is the xmlns:whiz attribute being added to the <html> element??
I tried having some other namespace declaration as xmlns:jaya="www.jaya.com" and i can see this also added in the attribute list for the <html> output element

I only got the old "FOUND" when I tested it on IE,
where did you got the above results? Theoretically, only <html>, <body>, <h1> tags will be inserted into the output in order to display the results.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev,
'XML Spy' behaves in the same way - All namespaces defined in the XSL style sheet, besides the xsl one, reach the output.
Cheers,
Dan
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim
You see those html tags when you see it in a notepad, or something like that and not the IE; IE knows how to intrepret those tags
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic