SoFunction
Updated on 2025-04-08

Generate static html pages on the server side using xmldom

In order to improve access speed, static htm pages are often needed to generate.
Generally, static htm pages can be generated using fso.
But if fso is prohibited or does not have permission to use fso, other methods are needed to solve it.
Using xmldom and using its save() method is a good solution.
Moreover, if the data is in XML format, using save() is faster than using fso, and the code reuse rate is also higher.

But it should be noted that:
When calling the() method, the default encoding method is "utf-8".
If the document output type is specified as "html", since it cannot specify the encoding type, when the data contains Chinese characters, you will find that all Chinese characters in the saved HTM data have become garbled.

Solution:
Mechanism: Usually, the browser does not explain tags other than the htm tag for pages of html type.
a. Specify the output document type as "xml"
b. Specify the encoding (encoding="gb2312")
c. Specify the retained indentation format (for easy reading)


examples:

/*** ***/
<%
dim cXMLFile, cXSLFile
dim oXML, XSL
dim oOutput
dim cHtmLFile, cOutputFile


cHtmLFile = ""
'cHtmLFile = "book_" & replace( replace( replace (now,":",""), "-", ""), " ", "") & ".htm"

cXMLFile = ("")
cXSLFile = ("")
cOutputFile = (cHtmLFile)

Set oXML = ("")
= false
(cXMLFile)

Set oXSL = ("")
= false
(cXSLFile)

Set oOutput = ("")
Call (oXSL, oOutput)

(cOutputFile)

Set oXML = Nothing
Set oXSL = Nothing
Set oOutput = Nothing

(cHtmLFile)
%>

/*** ***/
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href=""?>
<moonpiazza>
<book>
<Book Title>XML-based Development</Book Title>
<Price>42</Price>
<Author>Dan Wahlin/Wang Baoliang</Author>
</book>
<book>
<Book Title>UML Modeling Technology for XML Application</Book Title>
<Price>32</Price>
<Author>David Carlson/Zhou Jing Hou Yimeng Shen Jinhe, etc.</Author>
</book>
<book>
<Book Title>Extreme Programming Research</Book Title>
<Price>70</Price>
<Author>Giancarrio Succi/Michele Marchesi/Zhang Hui (translation)</Author>
</book>
<book>
<Book Title>Design Patterns</Book Title>
<Price>38</Price>
<Author>Erich Gamma/Richard Helm/Ralph Johnson/John Vlissides</Author>
</book>
</moonpiazza>

/*** ***/
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http:///1999/XSL/Transform" version="1.0">
<!-- The following sentence must -->
<xsl:output method="xml" encoding="gb2312" indent="yes"/>

<xsl:template match="/">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- by moonpiazza 2003.6.13-->
<body>
<table border="1">
  <tr>
   <xsl:for-each select="moonpiazza/book[position()=1]/*">   
    <td><xsl:value-of select="name()" /></td>   
   </xsl:for-each>
  </tr>
  <xsl:for-each select="moonpiazza/book">
   <tr>
    <xsl:for-each select="./*">   
     <td><xsl:value-of select="." /></td>   
    </xsl:for-each>
   </tr>
  </xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>