• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSLT OUTPUT

 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ref:
http://zvon.org/xxl/XSLTutorial/Output/example7_ch1.html
Problem:
I am not sure as to why does the display does not include
<i>Smith</i>
XSL:
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="employee">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="surname">
<i>
<xsl:value-of select="."/>
</i>
</xsl:template>

XML:
<source>
<employee>
<firstName>Joe</firstName>
<surname>Smith</surname>
</employee>
</source>
Output (As per http://zvon.org/xxl/XSLTutorial/Output/example7_ch1.html)
<b>
Joe
Smith
</b>
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because inside the "employee" template, you do not have a call to either <xsl:apply-templates/> or
<xsl:apply-templates select="surname"/>.
Without this, recursion stops and the "surname" template will never be called.
 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. However, then why do in the following case we also get the following in the output
"
<p style="color:red">I am </p>
<p>
<i>fine.</i>
</p>"
Example Ref: http://zvon.org/xxl/XSLTutorial/Output/example6_ch2.html
XML source
<source>
<bold>Hello, world.</bold>
<red>I am </red>
<italic>fine.</italic>
</source>

XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="bold">
<p>
<b>
<xsl:value-of select="."/>
</b>
</p>
</xsl:template>
<xsl:template match="red">
<p style="color:red">
<xsl:value-of select="."/>
</p>
</xsl:template>
<xsl:template match="italic">
<p>
<i>
<xsl:value-of select="."/>
</i>
</p>
</xsl:template>

</xsl:stylesheet>

Output
<p>
<b>Hello, world.</b>
</p>
<p style="color:red">I am </p>
<p>
<i>fine.</i>
</p>
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have no template matching "/" or "source". In the absence of such a template, XSLT applies the default rule, which is to recurse down to the children -- "bold", "red", and "italic".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic