Reputation: 927
I'm trying to print on html some XML code with XSLT, but it is not working properly.I'm still newbie and I'm not watching the problem.
This is my XSLT code:
<xsl:output method="html" encoding="UTF-8" />
<xsl:template match="/">
<div class="form-horizontal">
<xsl:for-each select="elements/element">
<xsl:sort data-type="number" select="order" />
<xsl:if test="@type='OUTPUT'">
<div class="row">
<div class="form-group">
<div class="{class}">
<xsl:value-of select="value"/>
</div>
</div>
</div>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="i">
<i>
<xsl:apply-templates />
</i>
</xsl:template>
<xsl:template match="b">
<b>
<xsl:apply-templates />
</b>
</xsl:template>
<xsl:template match="u">
<u>
<xsl:apply-templates />
</u>
</xsl:template>
<xsl:template match="del">
<del>
<xsl:apply-templates />
</del>
</xsl:template>
And this is my XML example code:
<elements>
<element type='OUTPUT'>
<value>
<b>
<u>Personal information</u>
</b>
</value>
<class>col-md-12 output</class>
<order>2</order>
</element>
</elements>
All works fine except the <b>
and <u>
tags.
This is what I'm obtaining:
My expected Output:
<div class="row">
<div class="form-group">
<div class="col-md-12 output">
<b>
<u>Personal information</u>
</b>
</div>
</div>
</div>
Someone knows where is the mistake?
Thanks in advance.
Upvotes: 0
Views: 58
Reputation: 29022
You are missing an xsl:apply-templates
in your first template.
Change it to
<div class="{class}">
<xsl:apply-templates />
<xsl:value-of select="value"/>
</div>
Upvotes: 1
Reputation: 167571
You will have to use xsl:apply-templates
if you want your templates to be applied e.g. instead of
<xsl:value-of select="value"/>
use
<xsl:apply-templates select="value"/>
Upvotes: 3