Project

Profile

Help

A beginer's question

Added by Anonymous almost 15 years ago

Legacy ID: #7423633 Legacy Poster: perl0101 (perl0101)

Hello everyone, I have written a xslt file to convert a text file to XML. When I run it from command line, it seems that SAXON-B only accepts xml source file as input. But XSLT 2.0 supports non-XML file. I want to knwo if the current version SAXON can do it? If so, how? thanks for your time, Yang


Replies (10)

Please register to reply

RE: A beginer's question - Added by Anonymous almost 15 years ago

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

The principal input file supplied on the command line (if supplied at all) must be an XML file. If you want to use a text file as input, you need to read it from within the stylesheet using the unparsed-text() function. It's then often convenient to enter the stylesheet at a named template, for example <xsl:template name="main">, which you can do by specifying -it:main on the command line.

RE: A beginer's question - Added by Anonymous almost 15 years ago

Legacy ID: #7423831 Legacy Poster: perl0101 (perl0101)

Thanks for your explanation. I appreciate your help. have a nice evening, Yang

RE: A beginer's question - Added by Anonymous almost 15 years ago

Legacy ID: #7423991 Legacy Poster: perl0101 (perl0101)

Thanks for your explanation. I appreciate your help. have a nice evening, Yang

RE: A beginer's question - Added by Anonymous almost 15 years ago

Legacy ID: #7425480 Legacy Poster: perl0101 (perl0101)

Dear Michael, Could you spend some time on my problem? I try the way discussed yesterday, but it is not correct. The output is included as follows. Can you help me to find the reason? Where can I find more detail document about Saxon? thanks, Yang D:\Saxon>java net.sf.saxon.Transform -s:d:\Saxon\stockdata.csv -xsl:d:
Saxon\transformSample.xsl -it:main -o:c:\Users\yangyang\Desktop\tempXML.xml Error on line 1 column 1 of stockdata.csv: SXXP0003: Error reported by XML parser: Content is not allowed in prolog. Transformation failed: Run-time errors were reported

RE: A beginer's question - Added by Anonymous almost 15 years ago

Legacy ID: #7425522 Legacy Poster: penguish (penguish)

Don't know if this helps or confuses (difficult to tell without more details): in the past, I've set these things up as a convenient script, like: ******************************************************************************** * markup.sh ******************************************************************************** #!/bin/sh export SAXON8_PATH=/sw/share/java/saxon8 export CALIBRATION_XSL=./markup.xsl java -jar $SAXON8_PATH/saxon8.jar -it main $CALIBRATION_XSL inputFile=$* ******************************************************************************** and then in my xsl, I have at the start: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes"/> <xsl:param name="inputFile" required="yes"/> <xsl:variable name="input_text" select="unparsed-text($inputFile,'UTF-8')"/> <xsl:template name="main"> ... rest of template ... then I can just type ./markup.sh <myfilename>

RE: A beginer's question - Added by Anonymous almost 15 years ago

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

As I said before: >The principal input file supplied on the command line (if supplied at all) must be an XML file. Your command line has -s:d:\Saxon\stockdata.csv and it's clear that this is not an XML file, therefore the XML parser is rejecting it. Just leave off this option - run without a principal source document.

RE: A beginer's question - Added by Anonymous almost 15 years ago

Legacy ID: #7425624 Legacy Poster: perl0101 (perl0101)

I change the command into the following: java net.sf.saxon.Transform -it:main -xsl:d:\Saxon\transformSample.xsl input=d:\Saxon\stockdata.csv In my xsl, I have the following: <xsl:param name="input" required="yes"/> <xsl:variable name="input-text" select="unparsed-text($input, 'UTF-8')"/> It looks work. thank you very much.

RE: A beginer's question - Added by Anonymous almost 15 years ago

Legacy ID: #7425642 Legacy Poster: perl0101 (perl0101)

Sorry, I get new problem. After I change the command line to: java net.sf.saxon.Transform -it:main -xsl:d:\Saxon\transformSample.xsl input=d:\Saxon\stockdata.csv The parser generates a new error message: XTDE1170: Invalid relative URI: Illegal character in opaque part at index 2: d:\Saxon\stockdata.csv: file:/d:/Saxon/transformSample.xsl in variable parsed-lines (file:/d:/Saxon/transformSample.xsl#21) Transformation failed: Run-time errors were reported I want to know what is the reason of it? Thanks for your time again.

RE: A beginer's question - Added by Anonymous almost 15 years ago

Legacy ID: #7425666 Legacy Poster: perl0101 (perl0101)

Hello, Thanks for your patience. I change the full path to the relative path (input=stockdata.csv) and it works now. But what is reason behind it? Besides the command line tool, I also want to use Java with Saxon to convert text file to xml. I want to know if there is already working examples. T thanks, Yang

RE: A beginer's question - Added by Anonymous almost 15 years ago

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

The first parameter to unparsed-text() is a URI, not a filename. So it should be input=file:///d:/Saxon/stockdata.csv or since it's in the same directory as the stylesheet input=stockdata.csv Generally, using filenames where URIs are expected sometimes works by accident, and sometimes doesn't (and you shouldn't rely on it). The reason it failed was that the string passed to unparsed-text() was treated as a relative URI, relative to the URI of the stylesheet, and the algorithm for resolving one URI against another doesn't handle backslashes. Michael Kay

    (1-10/10)

    Please register to reply