Error [FODC0002] when XSL returns sequence

Monday, 27 July 2015 · 2 messages · last reply 28 Jul 2015
MG
Maximilian Gärber27 Jul 2015 12:07 #
Hi, calling the test-xsl function does not work (might be a bug). I think returning a document fragment from xsl is not forbidden (at least exist-db permits it). The transform itself uses Saxon HE but this seems not related. -- start xqm -- xquery version "3.0";
module namespace _= "http://foo.org/test";
import module namespace xslt = "http://basex.org/modules/xslt";

declare variable $_:DATA := <foo>
    <bar1></bar1>
    <bar2></bar2>
  </foo>;

declare variable $_:XSL := <xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xhtml"/>
   <xsl:template match="/*/*">
     <div>some div</div>
   </xsl:template>
  </xsl:stylesheet>;
declare %rest:GET %rest:path("test-xsl") function _:test-xsl(){
   let $out := xslt:transform($_:DATA, $_:XSL)
   return $out
}; --- end xqm -- Message: Stopped at test-xsl.xqm, 26/31: [FODC0002] "" (Line 2): Markup im Dokument nach dem Root-Element muss ordnungsgemäß formatiert sein. Regards, Max
CG
Christian Grün28 Jul 2015 13:02 #
Hi Max, Right, the xslt:transform expects the result to be a single, well-formed XML document. However, you can retrieve the transformation result as text and then apply fn:parse-xml-fragment on it:
  fn:parse-xml-fragment(
    xslt:transform-text($DATA, $XSL)
  )
Hope this helps, Christian
Quoted text · Maximilian Gärber · 50 lines
On Mon, Jul 27, 2015 at 12:07 PM, Maximilian Gärber <mgaerber at arcor.de> wrote: > Hi, > > calling the test-xsl function does not work (might be a bug). I think > returning a document fragment from xsl is not forbidden (at least > exist-db permits it). > > The transform itself uses Saxon HE but this seems not related. > > -- start xqm -- > > xquery version "3.0"; > > module namespace _= "http://foo.org/test"; > import module namespace xslt = "http://basex.org/modules/xslt"; > > declare variable $_:DATA := <foo> > <bar1></bar1> > <bar2></bar2> > </foo>; > > declare variable $_:XSL := <xsl:stylesheet version="2.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="xhtml"/> > <xsl:template match="/*/*"> > <div>some div</div> > </xsl:template> > </xsl:stylesheet>; > > declare > %rest:GET > %rest:path("test-xsl") > function _:test-xsl(){ > > let $out := xslt:transform($_:DATA, $_:XSL) > return $out > > }; > > --- end xqm -- > > > Message: > > Stopped at test-xsl.xqm, 26/31: > [FODC0002] "" (Line 2): Markup im Dokument nach dem Root-Element muss > ordnungsgemäß formatiert sein. > > > Regards, Max

⚡Generated with XQuery