简体   繁体   English

使用XSL和Java样式将xml转换为html时,包含html数据的xml元素消失

[英]Xml element which contains html data when transforming xml to html using xsl and java styles are disappearing

I am facing an issue with the transform method on public abstract class Transformer. 我在公共抽象类Transformer上的transform方法面临一个问题。

I need to generate e-mails in Java, so i am using the above tranformer class and converting XML to HTML using XSL but one of the XML elements contains HTML code like below: 我需要用Java生成电子邮件,所以我使用上面的tranformer类并使用XSL将XML转换为HTML,但其中一个XML元素包含如下所示的HTML代码:

<data>
   <message>
  <font color="red">This is font color</font><br></br>
  <p>this is paragraph</p>
</message>
</data>

The XSL I used is below: 我使用的XSL如下:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<html>
  <body>

<xsl:template match="/">
        <td><xsl:value-of select="/data/message"/></td>
</xsl:template>
</xsl:stylesheet>
   </body>
  </html>

Now the email font color red is not appearing and the br tag is also not working, but some data is appearing from the same line. 现在,电子邮件字体颜色红色没有出现,并且br标签也不起作用,但是某些数据从同一行出现。

Can someone help me with this please. 请有人帮我这个。

xsl:value-of only outputs the text value of a node, and will not copied any descendant elements like br or font . xsl:value-of仅输出节点的文本值,不会复制任何后代元素,如brfont You could be using xsl:copy-of here, which will copy them. 您可能在此处使用xsl:copy-of ,它将复制它们。

Try this XSLT 试试这个XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
      <body>
        <table>
          <tr>
            <td><xsl:copy-of select="/data/message/node()"/></td>
          </tr>
        </table>
       </body>
      </html>
    </xsl:template>
</xsl:stylesheet>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM