Coming from this XML :
<log> <found> <color bgcolor="red">This is a silly <u>dummy</u> text with <color color="green">colored</colored> words and some <b>emphasized</b> ones</color> </found> <notfound> This is a silly <color color="red">stupid</color> text </notfound> </log>
I must produce this HTML :
<p>Found : <pre><span style="background-color:red;">This is a silly <u>dummy</u> text with <span style="color:green;">colored</span> words and some <b>emphasized</b> ones</span></pre></p> <p>Not Found : <pre>This is a silly <span style="color:red;">stupid</span> text</pre></p>
I tried to achieve this with :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="UTF-8"/> <xsl:apply-templates select="/log"/> <xsl:template match="log"> <xsl:apply-templates select="found"/> <xsl:apply-templates select="notfound"/> </xsl:template> <xsl:template match="found"> <xsl:if test=". != ''"> <p>Found : <pre><xsl:apply-templates name="./color"/></pre></p> </xsl:if> </xsl:template> <xsl:template match="notfound"> <xsl:if test=". != ''"> <p>Not found : <pre><xsl:apply-templates name="./color"/></pre></p> </xsl:if> </xsl:template> <xsl:template match="*/color"> <span> <xsl:attribute name="style"> <xsl:if test="./@color != ''"> color:<xsl:value-of select="./@color"/>; </xsl:if> <xsl:if test="./@bgcolor != ''"> background-color:<xsl:value-of select="./@bgcolor"/>; </xsl:attribute> <xsl:apply-templates select="./color"/> <xsl:copy-of select="text()"/> </span> </xsl:template> </xsl:stylesheet>
But it fails by stripping everything that may be within <u>
or <b>
or <i>
it may found (see <found>
) or putting every colored stuff before all other content (see <notfound>
) :
<p>Found : <pre><span style="background-color:red;">This is a silly text with <span style="color:green;">colored</span> words and some ones</span></pre></p> <p>Not Found : <pre><span style="color:red;">stupid</span>This is a silly text</pre></p>
Where am I wrong ?
Many thanks for any help !
No comments:
Post a Comment