Euro Dollar Frustration - XSLT, ASP

I

Iain Toft

I'm having problems displaying the ? euro dollar sign in XML produced
from an XSL transform.

SQL Server 2000 is used to produce XML (SELECT .. FOR XML) from a
database table containing data. The euro dollar displays fine in the
database table and in the SQL Server generated XML(snippet below) but
not in the transformed XML. In fact in this post it will probably
appear as a question mark anyway!

<transporttype>Vehicle types include Suzuki Samurai Jeep, closed
air-con cars, Jimny Jeeps with A/C, and Vitara convertible Jeeps with
A/C. Rates from ?70 to ?85 per day. The above rate includes 3rd party
insurance, unlimited kilometres and delivery to
hotels.</transporttype>

Having done the transform in ASP (below) the output XML file has the
'?' instead of the intended '?'. Having fiddled with encoding types
set in ASP code (see below) I coaxed a '¤' out of it!

ASP scripts are used to request the XML from database (stored
procedure) then transform it using XSLT:

Set objConn = CreateObject("ADODB.Connection")
Set objCMD = CreateObject("ADODB.Command")
set objDOM = CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
set objDOMOutput = CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
set objXSL = CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
objDOM.async = false
objXSL.async = false
.... some setting up db connections and SQL strings for objCMD here
objCMD.Properties("Output Stream") = objDOM
objCMD.Execute , , 1024
Dim objPI
set objPI = objDom.createProcessingInstruction("xml", "version='1.0'
encoding='UTF-8'")
objDom.insertBefore objPI, objDom.childNodes(0)
objXSL.load(arrStyleSheet(i))
objDOM.transformNodeToObject objXSL, objDOMOutput

the transformed xml is then passed to the function:

asCreateFile(lcase(strFilePath), lcase(strFileName),
asDOM2XML(objDOMOutput))

function asCreateFile(path, name, content)
Dim objStream
asCreateFile = false
if asCreatePath(path) then
set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 2
objStream.Charset = "iso-8859-1"
objStream.Open
objStream.writetext(content)
objStream.SaveToFile path & name, 2
objStream.Close
Set objStream = nothing
asCreateFile = true
end if
end function

Not entirely sure what asDOM2XML function does but here it is for all
those interested:

function asDOM2XML(objDOM)
'/* used to be: objDOMOutput.firstChild.xml &
replace(objDOMOutput.childNodes(1).xml,chr(13)+chr(10),"<br/>")
if objDOM.childNodes.length > 1 then
asDOM2XML = objDOM.firstChild.xml &
replace(objDOM.lastChild.xml,chr(13)+chr(10),"<br/>")
else
'asDOM2XML = replace(objDOM.firstChild.xml,chr(13)+chr(10),"<br/>")
asDOM2XML = objDOM.xml
end if
end function
 
R

Richard Tobin

I'm having problems displaying the ? euro dollar sign in XML produced
from an XSL transform.

I don't know anything about SQL or ASP, but I notice you have
objStream.Charset = "iso-8859-1"

The Euro symbol does not exist in iso-8859-1. Try using iso-8859-15
instead.

-- Richard
 
C

Chris Lovett

See http://msdn.microsoft.com/library/en-us/dnxml/html/xmlencodings.asp

The problem is most likely in the asCreateFile function which is saving the
DOM document to a file via the SaveToFile method on an ADODB.Stream object
specifying the an encoding that cannot handle the Euro character. This is
silly. You can easily save a DOM document to file using the DOM object's
own save method, and it is more likely to encode the document correctly that
way as follows:

objDOMOutput.save(path);

It appears the author of this code was concerned about converting the
newlines in the xml markup to <br/> tags, perhaps in an attempt at having
the XML formatted properly in the browser.

Another way to achieve this is to wrap the XML output in <pre> tags. Or if
you really still need to call asDOM2XML then you could "reload" this string
into the DOM object so you can use the DOM object to save the xml to disk
properly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top