XSLT which output non-xml text in XProc

Questions about XML that are not covered by the other forums should go here.
serioadamo97
Posts: 22
Joined: Tue Oct 17, 2017 5:05 pm

XSLT which output non-xml text in XProc

Post by serioadamo97 » Tue Feb 27, 2018 8:11 pm

I have a XSLT to generate code
text.xsl:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template name="main">
// Code generated xxxxx
// .......
class Test
{
}
</xsl:template>
</xsl:stylesheet>
And a XProc
test.xpl

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
<p:output port="result" primary="false">
<p:pipe port="result" step="test"/>
</p:output>

<p:xslt name="test" template-name="main">
<p:input port="source">
<p:empty/>
</p:input>
<p:input port="stylesheet">
<p:document href="test.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
</p:declare-step>
When execute test.xpl, the error occured:
Engine name: Calabash XProc
Severity: error
Description: p:xslt returned non-XML result
Start location: 8:46

I read the document in w3c https://www.w3.org/TR/xproc/#c.xslt
It does not say that the output of p:xslt must be xml.

Is there any way to fix this issue ?

Thanks.

Radu
Posts: 7534
Joined: Fri Jul 09, 2004 5:18 pm

Re: XSLT which output non-xml text in XProc

Post by Radu » Wed Feb 28, 2018 12:32 pm

Hi,

I don't think there is a way to overcome this without wrapping your output text in an XML tag, you should read this part of the XProc specs:

https://www.w3.org/TR/xproc/#binary

I think that right now they are working on the XProc 3.0 standard which may have the support you want but I'm not sure.
There is an XProc users list if you want to ask around:

http://xproc.org/

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

dcramer
Posts: 160
Joined: Sat Aug 28, 2010 1:23 am

Re: XSLT which output non-xml text in XProc

Post by dcramer » Thu Mar 11, 2021 10:08 am

I know this is an old post, but if anybody comes across it (like me, the next time I forget how this works and google the error again), I thought I should clarify that you can store non-xml from xproc by using p:store, but, as Radu says, you must produce xml from the xslt step.

In this case, make sure that the output of your xslt does produce xml by wrapping the output in some dummy element, <root> or whatever.
Then in your p:store, use method="text'. The stored document will throw away that dummy root element. One advantage of outputting xml is that you can use logic in your xslt to set the xml:base on that root element and then store the resulting text file in that location. If you had just output a text file, there would be no xml:base to work with:

<!-- xslt step here -->

Code: Select all

    <p:store encoding="utf-8" indent="true" method="text">
        <p:input port="source">
            <p:pipe port="result" step="some-xsl-step"/>
        </p:input>
        <p:with-option name="href" select="base-uri(/*)"/>
    </p:store>
If you're producing other files using xsl:result-document you have to use p:store to get those files off the secondary port.

See also: https://stackoverflow.com/questions/133 ... -documents

Regards,
David

Radu
Posts: 7534
Joined: Fri Jul 09, 2004 5:18 pm

Re: XSLT which output non-xml text in XProc

Post by Radu » Thu Mar 11, 2021 10:21 am

Hi David,

Thanks for updating this thread.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply