Forum Moderators: open
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html" encoding="utf-8"/><xsl:template match="b">
<fo:inline font-style="bold">
<xsl:apply-templates />
</fo:inline>
</xsl:template>
<xsl:template match="i">
<fo:inline font-style="italic">
<xsl:apply-templates />
</fo:inline>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="bios/bio">
<div id="bios">
<div style="float:left; padding-right:12px;"><img src="bios/im/{image}"/></div>
<h4><xsl:value-of select="name"></xsl:value-of></h4>
<br />
<h5><xsl:value-of select="title"></xsl:value-of></h5>
<br /><br />
<div style="text-align:justify"><xsl:value-of select="description"/></div>
<br /><br />
<span class="bio_comment"><xsl:apply-templates select="comment"/></span>
</div>
<br /><br /><br />
</xsl:for-each>
</xsl:template>
<xsl:template match="br"><br/></xsl:template>
</xsl:stylesheet>
My XML looks like this:
<?xml version="1.0" encoding="utf-8"?><bios>
<bio>
<name>My Name</name>
<title>My Title</title>
<image>image.jpg</image>
<description>
tex text <i>This should be italic </i> text text
</description>
</bio>
</bios>
Everything works great, but nothing appears italic...
Any thoughts/suggestions?
DOC for xsl:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html" encoding="utf-8"/>
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">
<xsl:for-each select="bios/bio">
<div id="bios">
<div style="float:left; padding-right:12px;"><img src="bios/im/{image}"/></div>
<h4><xsl:value-of select="name"></xsl:value-of></h4>
<br />
<h5><xsl:value-of select="title"></xsl:value-of></h5>
<br /><br />
<div style="text-align:justify"><xsl:value-of select="description"/></div>
<br /><br />
<span class="bio_comment"><xsl:apply-templates select="comment"/></span>
</div>
<br /><br /><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
In the XML, you need to designate the description as CDATA - this means it's treated as a whole like Character Data, and elements within it are not interpreted as additional nodes in the XML.
Change the XML slightly, so it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<bios>
<bio>
<name>My Name</name>
<title>My Title</title>
<image>image.jpg</image>
<description>
[red]<![CDATA[[/red]tex text <i>This should be italic </i> text text[red]]]>[/red]
</description>
</bio>
</bios>
Then, you need to add to the XSLT, so it doesn't turn those angle-brackets into < and >. To do that, you add the "disable-output-escaping" attribute to that element. This is important when outputting text formatted with HTML.
The XSLT looks like this:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">
<xsl:for-each select="bios/bio">
<div id="bios">
<div style="float:left; padding-right:12px;"><img src="bios/im/{image}"/></div>
<h4><xsl:value-of select="name"></xsl:value-of></h4>
<br />
<h5><xsl:value-of select="title"></xsl:value-of></h5>
<br /><br />
<div style="text-align:justify"><xsl:value-of select="description" [red]disable-output-escaping="yes"[/red]/></div>
<br /><br />
<span class="bio_comment"><xsl:apply-templates select="comment"/></span>
</div>
<br /><br /><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Finally when you do the transformation, the HTML will come out with <i> tags intact.
<div xmlns:fo="http://www.w3.org/1999/XSL/Format" id="bios"><div style="float:left; padding-right:12px;"><img src="bios/im/image.jpg"></div>
<h4>My Name</h4>
<br>
<h5>My Title</h5>
<br>
<br>
<div style="text-align:justify">
tex text <i>This should be italic </i> text text
</div>
<br>
<br>
<span class="bio_comment"></span>
</div><br><br><br>