When you click English, German, or Japanese, hello.asp runs again. The three buttons have the same NAME attribute, BTN. This time, the name of the button you click is captured and assigned to the passedValue variable, and the value of passedValue is replaced by the two-letter identifier for the selected language.
passedValue = Request.Form("BTN")
Select Case UCASE(passedValue)
Case "ENGLISH" passedValue="en"
Case "GERMAN" passedValue="de"
Case "JAPANESE" passedValue="ja"
end select
Next the code instantiates four instances of the XML DOM and one instance of the FileSystemObject object. The presence of a FileSystemObject object allows any new XML files that are built to be saved to a file on the server.
Set xmlArena = Server.CreateObject("Microsoft.XMLDOM")
Set xmlLingo = Server.CreateObject("Microsoft.XMLDOM")
Set xmlResult = Server.CreateObject("Microsoft.XMLDOM")
Set xslResult = Server.CreateObject("Microsoft.XMLDOM")
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
The cached XMLDOM objects are loaded with the content of the files specified in the URL. The xmlArena object is loaded with the nonlocalized XML data from arena.xml and the xmlLingo object is loaded with the content of de_lingo.xml, en_lingo.xml, or ja_lingo.xml depending on which language button you clicked. The xslResult object is the result.xsl file that provides transformation of the XML data.
URL = Server.MapPath("arena.xml")
xmlArena.load(URL)
URL = Server.MapPath(passedValue & "_lingo.xml")
xmlLingo.load(URL)
URL = Server.MapPath("result.xsl")
xslResult.load(URL)
The error-checking routine, parseError, is called for each of the above-mentioned XMLDOM objects, and any error is written to the browser.
The root nodes of the arena and lingo files are assigned to variables.
Set xmlARoot = xmlArena.documentElement
Set xmlLRoot = xmlLingo.documentElement
The last URL points to the file (de_result.xml, en_result.xml, or ja_result.xml) that holds the result of merging the arena file (arena.xml) and the lingo file for the selected language.
URL = Server.MapPath(passedValue & "_result.xml")
When the merged arena and lingo file for the selected language (for example, de_result.xml for German) does not exist, the getXML subroutine is called to build the new merged result file and this file is saved on the server. If the result file exists, it is loaded into the xmlResult XML document. The second True in the second line of the following code fragment indicates this file is saved in Unicode format.
If Not oFS.FileExists(URL) Then
Set tStrm = oFS.CreateTextFile(URL,True,True)
Set xmlResult.documentElement = xmlARoot
Set xmlRoot = xmlARoot
Call getXML(xmlRoot)
tStrm.WriteLine(xmlResult.xml)
tStrm.Close()
Else
xmlResult.load(URL)
Call parseError(xmlResult)
End If
The three languages (English, German, and Japanese) featured in the Hello World XML application use two different code pages: 1252 for English and German, and 932 for Japanese. The CodePage property of the Internet Explorer Session object is assigned the appropriate value for the language the user selects.
strNode = "//UIElement[@CODEPAGE]"
Set Element = xmlResult.selectSingleNode(strNode)
Session.CodePage = CInt(Element.getAttribute("CODEPAGE"))
Now that the merged XML file exists, the transformNode method of xmlResult (an XMLDOM object) applies result.xsl and the resulting values are written to the Web page. Using result.xsl describes what XSL contributes to the Hello World XML application.
Response.write xmlResult.transformNode(xslResult) 'display resulting htm