我想在CDATA块中为< p>解析HTML.标签,并在单独的表格行中将其输出.但是我不太清楚,想知道是否有人可以帮助我?
我一直试图解析HTML,但无法弄清楚如何解析它,而不能简单地将其视为字符数据.我很确定我无法使用XSL 1.0做到这一点,如果需要的话我可以使用2.0.
XML格式
<XML_FILE> <NOTE> <TEXT TITLE="TEST"> <![CDATA[<p>first p tag and <strong>bold</strong></p><p>second p tag and <u>underline</u></p>]]> </TEXT> </NOTE> </XML_FILE>
@H_403_13@XSL
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="NOTE"> <div class="tableWrapper"> <table class="body"> <xsl:apply-templates select="TEXT"/> </table> </div> </xsl:template> <xsl:template match="TEXT"> <xsl:value-of select="." disable-output-escaping="yes"/> </xsl:template> </xsl:stylesheet>
@H_403_13@输出量
<div class="tableWrapper"> <table class="body"><p>first p tag and <strong>bold</strong></p><p>second p tag and <u>underline</u></p></table> </div>
@H_403_13@期望的输出
<div class="tableWrapper"> <table class="body"> <tr><td><p>first p tag and <strong>bold</strong></p></td></tr> <tr><td><p>second p tag and <u>underline</u></p></td></tr> </table> </div>
@H_403_13@提供所需输出的最终样式表
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all" version="3.0"> <xsl:mode on-no-match="shallow-copy"/> <xsl:output method="html" indent="yes" html-version="5"/> <xsl:strip-space elements="*"/> <xsl:template match="XML_FILE"> <xsl:apply-templates/> </xsl:template> <xsl:template match="NOTE"> <div class="tableWrapper"> <table class="body"> <xsl:apply-templates select="parse-xml-fragment(TEXT)/node()"/> </table> </div> </xsl:template> <xsl:template match="p"> <tr> <td> <xsl:next-match/> </td> </tr> </xsl:template> </xsl:stylesheet>
@H_403_13@
最佳答案