Using XSL to output a CDATA annotation in an XML document as an HTML text _xml sample

Source: Internet
Author: User
Tags cdata xsl
Sample code
1. Test.xml
Copy Code code as follows:

<?xml version= "1.0" encoding= "gb2312"?>
<?xml-stylesheet href= "test.xsl" type= "text/xsl"?>
<entry>
<title>entry with images</title>
<date>august, 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[<p>class= "Archive" align= "right" src= "http://alazanto.org/images/sample.jpg"
alt= "Photograph of a flower, just for show"/>mauris Felis elit, varius
Quis, Pulvinar vel, sodales vehicula, MI. Nunc elementum, Pharetra elit.
</p>]]>
</body>
<more 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
Copy Code code as follows:

<?xml version= "1.0"?>
<xsl:stylesheet xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" version= "1.0" >
<xsl:template match= "/entry" >
<body>
<xsl:value-of select= "title"/>
<xsl:value-of select= "Body" disable-output-escaping= "yes"/>

</body>
</xsl:template>
</xsl:stylesheet>


The key lies in the use of namespaces xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" and output plus disable-output-escaping= "yes"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.