XML, XSL to convert text to identical html

Posted on 2003-03-30
Medium Priority
Last Modified: 2009-07-29
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.


Question by:joex
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 8238031

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,


Accepted Solution

sparkplug earned 2000 total points
ID: 8238348
Please close your pevious question: http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20498055.html


Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question