XML, XSL to convert text to identical html

I would like to know how to do the following:
   - method to convert a non-XML text file into an xml file such that:
         the xml has as few tags as possible
         the text file is changed as little as possible

   - XSL that processes the XML so that the resulting HTML displays the original text,
     with the same line breaks, and column spacing (using a fixed-width font) as are found in the original text.  That is, the HTML looks identical to the original text file.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I don't get why you need to convert this into XML first, but here's an example of how you would do this using ASP:

sTextFile = "c:\test.txt"
sXSLFile = "c:\test.xsl"

'Get the contents of the text file.
Const ForReading = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTS = oFSO.OpenTextFile(sTextFile, ForReading)
s = oTS.ReadAll

'add minimum tags to make XML
sXML = "<text><![CDATA[" & s & "]]></text>"

'Load the XML into a DOM
Set oXMLDom = Server.CreateObject("MSXML2.DOMDocument.4.0")
oXMLDom.async = false

Call oXMLDom.LoadXML(sXML)

'Load the XSL file and check for errors
Set oXSLDom = Server.CreateObject("MSXML2.DOMDocument.4.0")
oXSLDom.async = false

sXSLFile = Server.MapPath(sXSLFile)
If Not oXSLDom.Load(sXSLFile) Then
    Set oErr = oXSLDom.parseError
    sErrMsg = "XML Parsing Error. File: " & oErr.url & "  Reason : " & oErr.reason & " Line: " & oErr.line & ", Character: " & oErr.linepos & ", Text: " & oErr.srcText
    Err.Raise 999, sErrMsg
End If
'Transform the XML using the XSL and write the output
Response.Write oXMLDom.transformNode(oXSLDom)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="html"/>
     <xsl:template match="/">
          <html><body><pre style="font-family: courier new"><xsl:value-of select="text" /></pre></body></html>

Hope this helps,

Please close your pevious question: http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20498055.html


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.