Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:15:11+00:00 2026-06-04T06:15:11+00:00

I am trying to convert plain text files to XML files using XSLT. I

  • 0

I am trying to convert plain text files to XML files using XSLT. I started with CSV files, because that is a well-known file format that I could start Googling examples on.

I stumbled onto this: http://ajwelch.blogspot.com/2007/02/csv-to-xml-converter-in-xslt-20.html, which also points at http://andrewjwelch.com/code/xslt/csv/csv-to-xml_v2.html.

Those links contain what is, supposedly, an XSLT (2.0) that can take a CSV file and convert it to an XML file.

…Except it doesn’t actually work.

I set it up in my Maven Eclipse project, downloaded the latest Saxon dependency (9.4 HE) and tried to use it. I was met with this error:

Error on line 1 column 1 of csv.csv:

SXXP0003: Error reported by XML parser: Content is not allowed in prolog.

That seems to indicate to me that when it began parsing the file, it hit the first character, found it wasn’t a < character, exclaimed to itself "This isn’t an XML file! Double-yew tee eff, mate!" and blew up. Which kind of runs contrary to idea that this XSLT is supposed to work on files that are not XML (namely, CSV files instead). Forcing you to wrap your non-XML in an XML tag to have it work completely defeats the purpose.

At first I thought maybe the problem was that I wasn’t using the Saxon jar directly on the command line like the example. So I did just that. The result was something quite familiar:

Error on line 1 column 1 of csv.csv:

SXXP0003: Error reported by XML parser: Content is not allowed in prolog.

I thought that perhaps since I was using a newer version, I needed to go back and use the version that the example was originally written under. So I went back to SaxonB 9.1.0.8 and tried it both in Eclipse and on the command line. Care to guess what happened?

Error on line 1 column 1 of csv.csv:

SXXP0003: Error reported by XML parser: Content is not allowed in prolog.

I discovered that if I wrap the entire contents of the CSV file in a dummy xml tag (e.g. <whatever>item1,item2,item3</whatever>) it starts to almost work (it at least makes it past the first character and I start to get a different error farther along in the process).

So why the hell doesn’t this XSLT work? Why does the blog its posted on (and all of the attendant comments in the attached comment section) seem to indicate that it does? I also found it referenced here in the Ubuntu help documentation, and as the accepted answer on this StackOverflow question. How is that possible? It doesn’t work!

So either everyone on the entire Internet is lying to each other and/or themselves in a giant conspiracy designed to enrage me, or there is some very simple, integral step I am just missing that is required to make Saxon use that XSLT to convert a CSV file to an XML file.

So, anybody know which it is?

Edit: pgfearo’s answer accepted. The original contents of this "Edit" section is now it’s own question here: Saxon in Java: XSLT for CSV to XML

Edit 2: If anyone is curious as to what my XSLT ended up looking like, that ended up in a different question here: XSLT remove() function

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:15:12+00:00Added an answer on June 4, 2026 at 6:15 am

    I don’t think it’s a conspiracy – you haven’t included the Saxon command line you used but I suspect you’re calling the transform with csv.csv as the source of the transform. Because this isn’t an XML file you will get an XML parser error such as you’ve shown.

    The XSLT stylesheet you reference has an entry template called ‘main’, use the -it option on the command line to set ‘main’ as the initial template. With this set, you now don’t need to supply a source for the transform. The Saxon command line options are documented here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert a large number of files from a plain text layout
In ASP.Net (with C#) I'm trying to create a .DAT file with plain text
I'm trying to convert HTML to plain text. Is it efficient? Am I missing
I'm using php to take xml files and convert them into single line tab
All, I am trying to identify plain text files with Mac line endings and,
I'm trying to convert my sample HTML output into a plain text but I
I'm trying to put together a Multilingual Text Calculator using just plain Javascript (not
i´m using subsonic 3 trying convert a SQL2008 project to MySQL. when the projects
I need to be able to convert RTF or HTML to Markdown-syntaxed plain text
I am trying to configure HTMLPurifier to only display external links as plain text.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.