On another post, I received a great response from Michael Kay to my question concerning displaying XML data with HTML tags:
Quote:
quote:What methods exist with 1.0 that display tags within an XML tag as literal HTML?
Example:
<root>
<element>
<child>
<h1>TEST</h1>
<p>This is a test</p>
<p>This is only a test</p>
</child>
</element>
</root>
transforms to this using an XSLT stylesheet:
<html>
<body>
<h1>TEST</h1>
<p>This is a test</p>
<p>This is only a test</p>
</body>
</html>
Concerning your question:
<xsl:template match="child">
<xsl:copy-of select="*"/>
</xsl:template>
Michael Kay
|
This method has worked great except for one little thing. The <p> tags don't display as paragraphs, but all of the other HTML tags work fine (i.e.[list], <li>, <br />, etc.). I've tried two different methods, but neither of them work. I'm adding examples of my XML doc, XSLT stylesheet, and HTML output at the bottom of this post. If anyone can see what I'm doing wrong, and steer me in the right direction, it would be greatly appreciated. Thanks.
P.S. I've also tried changing the output from "xml" to "html", but that also had no effect on the <p>...</p> tags.
XML Doc:
<root>
<pageinfo>
<description>
<p>This is an example description.</p>
<p>It contains no real data.</p>
</description>
</pageinfo>
</root>
METHOD #1
XSLT Stylesheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="root/pageinfo">
<xsl:copy-of select="description" />
</xsl:for-each>
HTML Output:
<html>
<body>
<description>
<p>This is an example description.</p>
<p>It contains no real data.</p>
</description>
</body>
</html>
Page Display:
This is an example description. It contains no real data.
METHOD #2
XSLT Stylesheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="root/pageinfo/description">
<xsl:copy-of select="p" />
</xsl:for-each>
HTML Output:
<html>
<body>
<p>This is an example description.</p>
<p>It contains no real data.</p>
</body>
</html>
Page Display:
This is an example description. It contains no real data.
KWilliams