Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

XML, XSL to convert text to identical html

Posted on 2003-03-30
2
Medium Priority
?
161 Views
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.

Thanks,

Tim
   
0
Comment
Question by:joex
  • 2
2 Comments
 
LVL 9

Expert Comment

by:sparkplug
ID: 8238031
Hi,

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:


test.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
oTS.Close

'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)
%>


test.xsl
--------
<?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>
     </xsl:template>
</xsl:stylesheet>

Hope this helps,

>S'Plug<
0
 
LVL 9

Accepted Solution

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

>S'Plug<
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Screencast - Getting to Know the Pipeline
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

580 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