Analysis of two schemes of CMS Content management system

Source: Internet
Author: User
Tags format implement xmlns xsl xsl file client
Content Management System last articleTalked about how XSL and XML are browsed on the client side. It is also a form of content publishing for CMS content management systems, i.e. XSL (template) +xml (content).

But the reality is not supported by the client browser, this will also give the server a certain amount of load, the best way to reduce the server service load is to fully implement the static content access mechanism, of course, this requires the XSL and XML to generate HTML or shtml.

This is the second form of HTML or shtml that is called CMS Content Management system content publishing.

There are many ways to implement in Java, first of all, to produce XSL files, that is, template files.

Of course we first want to unify the coding, all the file code is "UTF-8", conforms to the globalization standard. The resulting file encoding format is "UTF-8", the database encoding format is "UTF-8", the automatically generated XSL file, XML file, HTML file, shtml file format must be "UTF-8", of course, also include the declaration inside the file must also be "UTF-8", Of course, please do not confuse the file encoding format and file internal declarations, I think beginners are the easiest to confuse. The file encoding format is the property of the file, the file itself is generated by what encoding format, and the file internal declaration refers to the file content also need to develop coding.

The purpose of course is very simple and clear, to prevent the emergence of everyone's headache garbled ~

Next, we'll talk about two scenarios for CMS Content Management systems: Xsl+xml and HTML (i), which illustrate the Java implementation of XSL template files.

XSL file: test.xsl

<?xml version= "1.0" encoding= "UTF-8"?
<xsl:stylesheet xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" version= "1.0"
<xsl:output method= "html"/>
<xsl:template match= "/article"
<table cellspacing= "1" cellpadding= "1" width= "border=" 1 ""
<tbody>
<tr>
<td> <xsl:value-of select= "title"/> </td>
<td> <xsl:value-of select= "click"/> </td>
</tr>
<tr>
<td> <xsl:value-of select= "date"/> </td>
<td> <xsl:value-of select= "Author"/> </td>
</tr>
<tr>
<td> <xsl:value-of select= "content" disable-output-escaping= "yes"/> </td>
<td> Test by Glandjacky </td>
</tr>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
First you must obtain a string xslcontent that you want to convert to XSL code

Using dom4j to implement XSL

The head of the XSL code

String xsl_head = "<?xml version=\" 1.0\ "encoding=\" utf-8\ "><!"? DOCTYPE Root [! ENTITY nbsp \ "\" >]><xsl:stylesheet xmlns:xsl=\ "http://www.w3.org/1999/xsl/transform\" version=\ "1.0\" ><xsl:output Method=\ "html\"/><xsl:template match=\ "/root\" ";

The end of the XSL code
String xsl_end = "</xsl:template> </xsl:stylesheet>";


Add the HTML code in the template file
if (xslcontent.substring (0,6). toUpperCase (). Equals ("<HTML>")) {
Xslcontent = xsl_head + xslcontent + xsl_end;
}else{
Xslcontent = Xsl_head + "<HTML> <meta content=\" text/html;charset=utf-8\ "http-equiv=\" content-type\ "/>" + xslContent+ " </HTML> + xsl_end;
}

Create document import Org.dom4j.DocumentHelper; Import org.dom4j.Document;
Document document = Documenthelper.parsetext (xslcontent);
Additional three parameters required after document creation

• Create a good document document

• Address string path to create an XSL file

• Create encoding format for files string charsetname

Document.setxmlencoding (CharsetName);
FileOutputStream fos = new FileOutputStream (path);
OutputStreamWriter OSW = new OutputStreamWriter (FOS, charsetname);
document.write (OSW);
Osw.close ();
Fos.close ();
So the XSL file is created.

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.