BaseX 12.0 is tripping on the XSLT transformation that outputs text, not XML

Sunday, 1 June 2025 · 4 messages · last reply 4 Jun 2025
Y
ykhabins1 Jun 2025 21:54 #

Hello,

It seems that BaseX 12.0 beta 2686758, and later, is tripping on the XSLT transformation that outputs text, not XML. I am using SaxonHE12-5J.

Even the following XQuery setting is not helping. declare option output:method 'text';

IMHO, BaseX should read the output:method attribute from an XSLT and handle it properly. method? = "xml" | "html" | "xhtml" | "text" | "json" | "adaptive" | eqname https://qt4cg.org/specifications/xslt-40/Overview.html#id-xsl-output-declaration

Below is an easy repro.

Process3.xslt is working (xsl:output method="xml") Process2.xslt is NOT working (xsl:output method="text")

Error: Stopped at C:/Program Files (x86)/BaseX/src/file, 10/15: [FODC0002] "" (Line 1): Content is not allowed in prolog.

XQuery ============= (: Outputs the result as xml. :) declare option output:method 'text';

declare variable $input as xs:string := 'e:\Temp\BaseX_XSLT\Input2.xml';
declare variable $stylesheet as xs:string := 'e:\Temp\BaseX_XSLT\Process2.xslt';

xslt:transform($input, $stylesheet)

input2.xml ============== <dummy>text</dummy>

Process3.xslt ================= <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="yes"/>

	<xsl:template match="/dummy">
		<xsl:copy-of select="."/>
	</xsl:template>
</xsl:stylesheet>

Process2.xslt ================ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" omit-xml-declaration="yes"/>

	<xsl:template match="/dummy">
		<xsl:value-of select="."/>
	</xsl:template>
</xsl:stylesheet>
GS
Graydon Saunders1 Jun 2025 23:49 #

11.9 (and SaxonHE-J 12.7) has the same issue, and continues to have the issue with the delivery-format option set on transform()

xslt:transform($input, $stylesheet,map{'delivery-format': 'raw'})
xslt:transform($input, $stylesheet,map{'delivery-format': 'serialized'})
xslt:transform($input, $stylesheet,map{'delivery-format': 'document'})

all give the same "not allowed in prolog" result.

Since setting the stylesheet to process3.xsl which ought to return

<dummy>text</dummy>

returns

text

instead, no matter if delivery-format is set or what it's set to if it is set, or if I assign the result to a variable typed item() and return that.

-- Graydon

Quoted text · ykhabins at bellsouth.net · 56 lines
On Sun, Jun 1, 2025, at 15:54, ykhabins at bellsouth.net wrote: > Hello, > > It seems that BaseX 12.0 beta 2686758, and later, is tripping on the XSLT transformation that outputs text, not XML. > I am using SaxonHE12-5J. > > Even the following XQuery setting is not helping. > declare option output:method 'text'; > > IMHO, BaseX should read the output:method attribute from an XSLT and handle it properly. > method? = "xml" | "html" | "xhtml" | "text" | "json" | "adaptive" | eqname > https://qt4cg.org/specifications/xslt-40/Overview.html#id-xsl-output-declaration > > Below is an easy repro. > > Process3.xslt is working (xsl:output method="xml") > Process2.xslt is NOT working (xsl:output method="text") > > Error: > Stopped at C:/Program Files (x86)/BaseX/src/file, 10/15: > [FODC0002] "" (Line 1): Content is not allowed in prolog. > > XQuery > ============= > (: Outputs the result as xml. :) > declare option output:method 'text'; > > declare variable $input as xs:string := 'e:\Temp\BaseX_XSLT\Input2.xml'; > declare variable $stylesheet as xs:string := 'e:\Temp\BaseX_XSLT\Process2.xslt'; > > xslt:transform($input, $stylesheet) > > input2.xml > ============== > <dummy>text</dummy> > > Process3.xslt > ================= > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="xml" omit-xml-declaration="yes"/> > > <xsl:template match="/dummy"> > <xsl:copy-of select="."/> > </xsl:template> > </xsl:stylesheet> > > Process2.xslt > ================ > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="text" omit-xml-declaration="yes"/> > > <xsl:template match="/dummy"> > <xsl:value-of select="."/> > </xsl:template> > </xsl:stylesheet> >
CG
Christian Grünin reply to ykhabins, 1 Jun 2025, 21:542 Jun 2025 11:16 #

Hi Yitzhak,

If your XSLT transformation returns something else than an XML document, you should use xslt:transform-text [1] to receive the generated result as string.

Hope this helps, Christian

[1] https://docs.basex.org/main/XSLT_Functions#xslt:transform-text

Quoted text · PM · 62 lines
On Sun, Jun 1, 2025 at 9:55 PM <ykhabins at bellsouth.net> wrote: > Hello, > > It seems that BaseX 12.0 beta 2686758, and later, is tripping on the XSLT > transformation that outputs text, not XML. > I am using SaxonHE12-5J. > > Even the following XQuery setting is not helping. > declare option output:method 'text'; > > IMHO, BaseX should read the output:method attribute from an XSLT and > handle it properly. > method? = "xml" | "html" | "xhtml" | "text" | "json" | "adaptive" | eqname > > https://qt4cg.org/specifications/xslt-40/Overview.html#id-xsl-output-declaration > > Below is an easy repro. > > Process3.xslt is working (xsl:output method="xml") > Process2.xslt is NOT working (xsl:output method="text") > > Error: > Stopped at C:/Program Files (x86)/BaseX/src/file, 10/15: > [FODC0002] "" (Line 1): Content is not allowed in prolog. > > XQuery > ============= > (: Outputs the result as xml. :) > declare option output:method 'text'; > > declare variable $input as xs:string := 'e:\Temp\BaseX_XSLT\Input2.xml'; > declare variable $stylesheet as xs:string := > 'e:\Temp\BaseX_XSLT\Process2.xslt'; > > xslt:transform($input, $stylesheet) > > input2.xml > ============== > <dummy>text</dummy> > > Process3.xslt > ================= > <xsl:stylesheet version="1.0" xmlns:xsl=" > http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="xml" omit-xml-declaration="yes"/> > > <xsl:template match="/dummy"> > <xsl:copy-of select="."/> > </xsl:template> > </xsl:stylesheet> > > Process2.xslt > ================ > <xsl:stylesheet version="1.0" xmlns:xsl=" > http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="text" omit-xml-declaration="yes"/> > > <xsl:template match="/dummy"> > <xsl:value-of select="."/> > </xsl:template> > </xsl:stylesheet> >
Y
ykhabins4 Jun 2025 03:20 #

Mr. Grun,

The xslt:transform-text() is working for me. Thanks a lot.

Regards, Yitzhak Khabinsky


⚡Generated with XQuery