XSL style sheet with sax-writer

subby

New Member
Hi There,

I have created a query that generates an XML file. But i also want to reference to a style sheet. I found in the forunm over here that i have to add this:

hSAXWriter:write-processing-instruction("xml-stylesheet", "type=""text/xsl"" href=""wo.xsl""").
but when i run it.

i receive this error:
WRITE-PROCESSING-INSTRUCTION method invalid while WRITE-STATUS is WRITE-IDLE.
(14609)

Can some help me? i'm pretty new to SAX-writer and the QAD documentation doesn't say anything about adding a stylesheet.

DEF VAR hSAXWriter AS HANDLE NO-UNDO.
DEF VAR lOK AS LOGICAL NO-UNDO.
CREATE SAX-WRITER hSAXWriter.
hSAXWriter:FORMATTED = TRUE.
hSAXWriter:ENCODING = "UTF-8".
hSAXWriter:strict = false.
cDEF VAR hSAXWriter AS HANDLE NO-UNDO.
DEF VAR lOK AS LOGICAL NO-UNDO.
CREATE SAX-WRITER hSAXWriter.
hSAXWriter:FORMATTED = TRUE.
hSAXWriter:ENCODING = "UTF-8".
hSAXWriter:strict = false.
hSAXWriter:write-processing-instruction("xml-stylesheet", "type=""text/xsl"" href=""wo.xsl""").
lOK = hSAXWriter:SET-OUTPUT-DESTINATION("file", "wo2-test.xml").
lOK = hSAXWriter:START-DOCUMENT().
lOK = hSAXWriter:START-ELEMENT("ProductionPlan").


lOK = hSAXWriter:SET-OUTPUT-DESTINATION("file", "wo2-test.xml").
lOK = hSAXWriter:START-DOCUMENT().
lOK = hSAXWriter:START-ELEMENT("ProductionPlan").
 

Cringer

ProgressTalk.com Moderator
Staff member
I've no idea, but have you tried moving the hSAXWriter:write-processing-instruction("xml-stylesheet", "type=""text/xsl"" href=""wo.xsl"""). down a line or two to see if that helps?
 

RealHeavyDude

Well-Known Member
Just guessing, but I think you need to replace the enclosing double quotes on the second parameter to a single quote, like:
Code:
hSAXWriter:write-processing-instruction("xml-stylesheet", 'type="text/xsl" href="wo.xsl"').
. The ABL cannot handle double double quotes correctly - but you can use quote and double quote as string terminators which might come in handy here.

Heavy Regards, RealHeavyDude.
 

subby

New Member
no also with the single quotus:
WRITE-PROCESSING-INSTRUCTION method invalid while WRITE-STATUS is WRITE-IDLE.
(14609)
 

RealHeavyDude

Well-Known Member
Forgot: Whenever you hard code a string that contains double quotes you must enclose it with quotes and vice versa. The API for the method you are using requires two parameters and the usage of ""some text"" is not correct syntax.

Heavy Regards, RealHeavyDude.
 

subby

New Member
to bad also with double quotus it gives the same error-message. Looks like i have to open the write status.

WRITE-PROCESSING-INSTRUCTION method invalid while WRITE-STATUS is WRITE-IDLE.
(14609)
 

RealHeavyDude

Well-Known Member
Never used it - therefore I am not 100% positive - but, to pin down the problem I would check the WRITE-STATUS attribute on the SAX object to see when it is not idle any more and move the offending statement down to be located after the first statement where the WRITE-STATUS has changed.

Heavy Regards, RealHeavyDude.
 

subby

New Member
I have added the line to the bottom of the script:

lOK = hSAXWriter:END-ELEMENT("ProductionPlan").
hSAXWriter:write-processing-instruction("xml-stylesheet", 'type="text/xsl"
href="wo.xsl"').
lOK = hSAXWriter:END-DOCUMENT().

Then it writes the stylesheet. But it enters it at the bottom of the xml. So i cannot use it.
 

subby

New Member
The problem is solved :).

I had to put the code after start-document. and added hSAXWriter:strict = false.

Code:
CREATE SAX-WRITER hSAXWriter.
hSAXWriter:FORMATTED = TRUE.
hSAXWriter:ENCODING = "UTF-8".
hSAXWriter:strict = false.
lOK = hSAXWriter:SET-OUTPUT-DESTINATION("file", "wo-test.xml").
lOK = hSAXWriter:START-DOCUMENT().
hSAXWriter:write-processing-instruction("xml-stylesheet", 'type="text/xsl"
href="wo.xsl"').
lOK = hSAXWriter:START-ELEMENT("ProductionPlan").

Thanks for thinking with me.
 
Top