Home > Article > Backend Development > XSL code example to output CDATA comments in XML as HTML text
To use the DOM to access XML files, you must link the XML file to an HTML web page.
Sample code
1. test.xml
<?xml version="1.0" encoding="gb2312"?> <?xml-stylesheet href="test.xsl" type="text/xsl"?> <entry> <title>entry with images</title> <date>August 09, 2003</date> <author>Kevin</author> <idnum>000033</idnum> <permalink>http://alazanto.org/xml/archives/000033.xml</permalink> <body xmlns:html="http://www.w3.org/1999/xhtml"><![CDATA[]]></more> <comment-link>http://alazanto.org/xml/archives/000033_comments.xml</comment-link> <comment-count>6</comment-count> </entry>
2. test.xsl
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/entry"><html><head></head><body><xsl:value-of select="title" /><xsl:value-of select="body" disable-output-escaping="yes"/> </body></html></xsl:template></xsl:stylesheet>
Outside of key It depends on using the namespace xmlns:xsl="www.w3.org/1999/XSL/Transform" and adding disable-output-escaping="yes" when outputting
Sample code
1. test.xml
<?xml version="1.0" encoding="gb2312"?> <?xml-stylesheet href="test.xsl" type="text/xsl"?> <entry> <title>entry with images</title> <date>August 09, 2003</date> <author>Kevin</author> <idnum>000033</idnum> <permalink>http://alazanto.org/xml/archives/000033.xml</permalink> <body xmlns:html="http://www.w3.org/1999/xhtml"><![CDATA[]]></more> <comment-link>http://alazanto.org/xml/archives/000033_comments.xml</comment-link> <comment-count>6</comment-count> </entry>
2. test.xsl
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/entry"><html><head></head><body><xsl:value-of select="title" /><xsl:value-of select="body" disable-output-escaping="yes"/> </body></html></xsl:template></xsl:stylesheet>
The key lies in the namespace used xmlns:xsl="http://www.w3.org/1999/XSL /Transform" and add disable-output-escaping="yes"
The above is the detailed content of XSL code example to output CDATA comments in XML as HTML text. For more information, please follow other related articles on the PHP Chinese website!