Project

Profile

Help

Maintenance: Planio will be observing a scheduled maintenance window this Tuesday, November 5, 2024 from 03:00 UTC until 06:30 UTC to perform urgent network maintenance in our primary data center. Your Planio account will be unavailable during this maintenance window.

Fixed length -> XML

Added by Anonymous over 16 years ago

Legacy ID: #5024061 Legacy Poster: matt_dowell (matt_dowell)

I created a style sheet to convert a fixed length file from our mainframe to an XML file. I based it off of an example I found here: http://www.topxml.com/xsltStylesheets/xslt_non_XML.asp When I run the transformation, I get the following error: Error on line 1 column 1 of file:///E:/tools/xslt2/FixedLengthTextToXML/medical.fixed: SXXP0003: Error reported by XML parser: Content is not allowed in prolog. org.xml.sax.SAXParseException: Content is not allowed in prolog. It seems like the Saxon is expecting XML as my input source, not a fixed length text file. Is there some way for me to tell it what to expect? Is this even possible with Saxon? Thanks, Matt Dowell


Replies (6)

Please register to reply

RE: Fixed length -> XML - Added by Anonymous over 16 years ago

Legacy ID: #5024088 Legacy Poster: David Lee (daldei)

If you look at the XML input from this web site http://www.topxml.com/xsltStylesheets/Stylesheets/NonXML/FixedLengthText/FixedLengthTextToXML/FixedLengthTextToXML.xml You will see that the description of the sample is not really accurate. The "file" is truely an XML file with a single <data> field. It looks like this: <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE data (View Source for full doctype...)> <data>ALFKI Alfreds Futterkiste Sales Representative 030-0074321 AROUT Thomas Hardy Sales Representative (171) 555-7788 BERGS Christina Berglund Order Administrator 0921-12 34 65</data> Saxon (or any XSLT processor to my knowlege) cannot read as input anything but an XML file.

RE: Fixed length -&gt; XML - Added by Anonymous over 16 years ago

Legacy ID: #5024226 Legacy Poster: Jesper Tverskov (jesper_tverskov)

You can use the unparsed-text() function to load the fixed length file. In that way XSLT 2.0 can transform not only XML but any text format. For an example of transforming fixed length to xml see: http://www.xmlplease.com/xsltcases-fixed2xml Cheers, Jesper Tverskov

RE: Fixed length -&gt; XML - Added by Anonymous over 16 years ago

Legacy ID: #5024241 Legacy Poster: matt_dowell (matt_dowell)

Ok, yeah thanks that solved it.

RE: Fixed length -&gt; XML - Added by Anonymous over 16 years ago

Legacy ID: #5024252 Legacy Poster: Michael Kay (mhkay)

The XSLT 1.0 example that you cite uses the technique of including the text file as an external entity into an XML file that adds a wrapper element to make it into well-formed XML. Actually, that's a highly dubious technique since it fails if the text file contains "<" or "&" characters. In XSLT 2.0 you can do this much more directly by reading the text file using the unparsed-text() function as Jesper suggests. A couple of points about his example, though. The fact that he's tokenizing using newline as a delimiter seems to have got lost somewhere - it looks like a space when displayed in the browser. I would suggest tokenize(unparsed-text('abc.txt'), '\r?\n') And he suggests that you have to supply an XML document as a dummy input - that's not true; you can run without a primary input by starting your stylesheet at a named template (use for example -it:main on the command line). Finally: this is an XSLT 2.0 coding question rather than a Saxon question. The right place for that is therefore the xsl-list at mulberrytech.com/

RE: Fixed length -&gt; XML - Added by Anonymous over 16 years ago

Legacy ID: #5024390 Legacy Poster: Jesper Tverskov (jesper_tverskov)

Yes, a named template can be used instead of a dummy input file to start the transformation in Saxon, but I prefer using the dummy for two reasons: The other major XSLT 2.0 processor, AltovaXML, does not support a named template as a starter and I like my stylesheets to work also there. Also some XML Editors when using Saxon have forgotten to include a dialog box for setting up the named template as starter. Oxygen is an example. We can do it in Stylus Studio but even this editor always also needs an input file! Cheers, Jesper Tverskov

RE: Fixed length -&gt; XML - Added by Anonymous over 16 years ago

Legacy ID: #5024448 Legacy Poster: Michael Kay (mhkay)

Well, you can always provide a fallback for lesser XSLT 2.0 processors by writing <xsl:template name="main" match="/"> so you can run with a dummy source document when your environment gives you no other option. Michael Kay

    (1-6/6)

    Please register to reply