Can't get `cdata-section-elements` to work at all for XSLT output

Wednesday, 1 August 2018 · 9 messages · last reply 2 Aug 2018
CG
Christian Grünin reply to Hugh Guiney, 1 Aug 2018, 23:171 Aug 2018 21:23 #
Hi Hugh, Welcome to the list. If you want to return the Saxon result as-is, you could try to use xslt:transform-text instead of xslt:transform. I’ll have a closer look at your second attempt next day. Best, Christian
Quoted text · Hugh Guiney · 104 lines
Hugh Guiney <hugh.guiney at gmail.com> schrieb am Mi., 1. Aug. 2018, 21:17: > Hello, > > First off, loving BaseX so far! Using it as the backend for an API I’m > building. However, I’m running into an issue. I’m trying to transform > my database XML into an RSS 2.0 feed. It’s mostly working fine, but I > can’t output CDATA content at all, which I need to do for > `content:encoded` elements. > > Specs: > > - BaseX 9.0.2 (started via basexserver script) > - Saxon-HE 9.8.0.12J from Saxonica > - java version "1.8.0_112" > - basex 0.9.0 (NodeJS) > - macOS Sierra 10.12.6 > > ### First Attempt > > I set `cdata-section-elements` in the XSLT. > > rss.xq: > ``` > xquery version "3.0"; > declare option output:omit-xml-declaration "no"; > > let $in := > <root> > <child>hello</child> > </root> > let $style := doc( 'rss.xslt' ) > return xslt:transform( $in, $style ) > ``` > > rss.xslt: > ``` > <?xml version="1.0" encoding="UTF-8"?> > <xsl:transform > version="3.0" > xmlns="http://backend.userland.com/rss2" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:content="http://purl.org/rss/1.0/modules/content/" > > > <xsl:output > omit-xml-declaration="no" > cdata-section-elements="content:encoded" > /> > <xsl:template match="/"> > <rss version="2.0"> > <content:encoded>hi</content:encoded> > <content:encoded><xsl:text>howdy</xsl:text></content:encoded> > <content:encoded><xsl:value-of select="//child" /></content:encoded> > </rss> > </xsl:template> > </xsl:transform> > ``` > > Result: > ``` > <?xml version="1.0" encoding="UTF-8"?> > <rss xmlns="http://backend.userland.com/rss2" > xmlns:content="http://purl.org/rss/1.0/modules/content/" > version="2.0"> > <content:encoded>hi</content:encoded> > <content:encoded>howdy</content:encoded> > <content:encoded>hello</content:encoded> > </rss> > ``` > > No CDATA sections. > > ### Second Attempt > > I set `cdata-section-elements` in the XQuery. > > rss.xq: > ``` > xquery version "3.0"; > declare namespace content = "http://purl.org/rss/1.0/modules/content/"; > declare option output:omit-xml-declaration "no"; > declare option output:cdata-section-elements "content:encoded"; > > let $in := > <root> > <child>hello</child> > </root> > let $style := doc( 'rss.xslt' ) > return xslt:transform( $in, $style ) > ``` > > rss.xslt: > [Unchanged] > > Result: > [XPST0081] No namespace declared for 'content:encoded'. > > Clearly I declared the namespace two lines up. > > This looks like a bug to me, but any help appreciated if I’ve missed a > step here. > > Thanks, > Hugh >
IL
Imsieke, Gerrit, le-texin reply to Hugh Guiney, 1 Aug 2018, 23:171 Aug 2018 21:50 #
Hi Hugh, The second version where you specify the serialization options in XQuery works for me (BaseX GUI 8.6.5 with Saxon PE 9.6.0.7):
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns="http://backend.userland.com/rss2"
xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
   <content:encoded><![CDATA[hi]]></content:encoded>
   <content:encoded><![CDATA[howdy]]></content:encoded>
   <content:encoded/>
</rss>
The first version cannot generate CDATA sections since the XSLT processor is not serializing anything; it’s the XQuery processor that serializes the result. The error that you are seeing, XPST0081, would be generated if there were no namespace declaration for the prefix 'content', maybe caused by an indistinguishable look-alike non-ASCII character in 'content'. Doesn’t seem to be the case. Maybe this is a bug that is specific to BaseX 9? Gerrit
Quoted text · Hugh Guiney · 104 lines
On 01.08.2018 21:17, Hugh Guiney wrote: > Hello, > > First off, loving BaseX so far! Using it as the backend for an API I’m > building. However, I’m running into an issue. I’m trying to transform > my database XML into an RSS 2.0 feed. It’s mostly working fine, but I > can’t output CDATA content at all, which I need to do for > `content:encoded` elements. > > Specs: > > - BaseX 9.0.2 (started via basexserver script) > - Saxon-HE 9.8.0.12J from Saxonica > - java version "1.8.0_112" > - basex 0.9.0 (NodeJS) > - macOS Sierra 10.12.6 > > ### First Attempt > > I set `cdata-section-elements` in the XSLT. > > rss.xq: > ``` > xquery version "3.0"; > declare option output:omit-xml-declaration "no"; > > let $in := > <root> > <child>hello</child> > </root> > let $style := doc( 'rss.xslt' ) > return xslt:transform( $in, $style ) > ``` > > rss.xslt: > ``` > <?xml version="1.0" encoding="UTF-8"?> > <xsl:transform > version="3.0" > xmlns="http://backend.userland.com/rss2" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:content="http://purl.org/rss/1.0/modules/content/" >> > <xsl:output > omit-xml-declaration="no" > cdata-section-elements="content:encoded" > /> > <xsl:template match="/"> > <rss version="2.0"> > <content:encoded>hi</content:encoded> > <content:encoded><xsl:text>howdy</xsl:text></content:encoded> > <content:encoded><xsl:value-of select="//child" /></content:encoded> > </rss> > </xsl:template> > </xsl:transform> > ``` > > Result: > ``` > <?xml version="1.0" encoding="UTF-8"?> > <rss xmlns="http://backend.userland.com/rss2" > xmlns:content="http://purl.org/rss/1.0/modules/content/" > version="2.0"> > <content:encoded>hi</content:encoded> > <content:encoded>howdy</content:encoded> > <content:encoded>hello</content:encoded> > </rss> > ``` > > No CDATA sections. > > ### Second Attempt > > I set `cdata-section-elements` in the XQuery. > > rss.xq: > ``` > xquery version "3.0"; > declare namespace content = "http://purl.org/rss/1.0/modules/content/"; > declare option output:omit-xml-declaration "no"; > declare option output:cdata-section-elements "content:encoded"; > > let $in := > <root> > <child>hello</child> > </root> > let $style := doc( 'rss.xslt' ) > return xslt:transform( $in, $style ) > ``` > > rss.xslt: > [Unchanged] > > Result: > [XPST0081] No namespace declared for 'content:encoded'. > > Clearly I declared the namespace two lines up. > > This looks like a bug to me, but any help appreciated if I’ve missed a > step here. > > Thanks, > Hugh >
CG
Christian Grün1 Aug 2018 21:59 #
Thanks, Gerrit, for testing the query with BaseX 8.6.5. I just tried 9.0.2 and 9.1 beta, and it runs successfully on my machine as well. The result:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns="http://backend.userland.com/rss2"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
version="2.0">
  <content:encoded><![CDATA[hi]]></content:encoded>
  <content:encoded><![CDATA[howdy]]></content:encoded>
  <content:encoded><![CDATA[hello]]></content:encoded>
</rss>
I get the reported error message only if I remove the namespace declaration from the query prolog: [XPST0081] No namespace declared for 'content:encoded'.
Quoted text · le-tex · 133 lines
On Wed, Aug 1, 2018 at 9:50 PM Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de> wrote: > > Hi Hugh, > > The second version where you specify the serialization options in XQuery > works for me (BaseX GUI 8.6.5 with Saxon PE 9.6.0.7): > > <?xml version="1.0" encoding="UTF-8"?> > <rss xmlns="http://backend.userland.com/rss2" > xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> > <content:encoded><![CDATA[hi]]></content:encoded> > <content:encoded><![CDATA[howdy]]></content:encoded> > <content:encoded/> > </rss> > > The first version cannot generate CDATA sections since the XSLT > processor is not serializing anything; it’s the XQuery processor that > serializes the result. > > The error that you are seeing, XPST0081, would be generated if there > were no namespace declaration for the prefix 'content', maybe caused by > an indistinguishable look-alike non-ASCII character in 'content'. > Doesn’t seem to be the case. Maybe this is a bug that is specific to > BaseX 9? > > Gerrit > > > On 01.08.2018 21:17, Hugh Guiney wrote: > > Hello, > > > > First off, loving BaseX so far! Using it as the backend for an API I’m > > building. However, I’m running into an issue. I’m trying to transform > > my database XML into an RSS 2.0 feed. It’s mostly working fine, but I > > can’t output CDATA content at all, which I need to do for > > `content:encoded` elements. > > > > Specs: > > > > - BaseX 9.0.2 (started via basexserver script) > > - Saxon-HE 9.8.0.12J from Saxonica > > - java version "1.8.0_112" > > - basex 0.9.0 (NodeJS) > > - macOS Sierra 10.12.6 > > > > ### First Attempt > > > > I set `cdata-section-elements` in the XSLT. > > > > rss.xq: > > ``` > > xquery version "3.0"; > > declare option output:omit-xml-declaration "no"; > > > > let $in := > > <root> > > <child>hello</child> > > </root> > > let $style := doc( 'rss.xslt' ) > > return xslt:transform( $in, $style ) > > ``` > > > > rss.xslt: > > ``` > > <?xml version="1.0" encoding="UTF-8"?> > > <xsl:transform > > version="3.0" > > xmlns="http://backend.userland.com/rss2" > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > xmlns:content="http://purl.org/rss/1.0/modules/content/" > >> > > <xsl:output > > omit-xml-declaration="no" > > cdata-section-elements="content:encoded" > > /> > > <xsl:template match="/"> > > <rss version="2.0"> > > <content:encoded>hi</content:encoded> > > <content:encoded><xsl:text>howdy</xsl:text></content:encoded> > > <content:encoded><xsl:value-of select="//child" /></content:encoded> > > </rss> > > </xsl:template> > > </xsl:transform> > > ``` > > > > Result: > > ``` > > <?xml version="1.0" encoding="UTF-8"?> > > <rss xmlns="http://backend.userland.com/rss2" > > xmlns:content="http://purl.org/rss/1.0/modules/content/" > > version="2.0"> > > <content:encoded>hi</content:encoded> > > <content:encoded>howdy</content:encoded> > > <content:encoded>hello</content:encoded> > > </rss> > > ``` > > > > No CDATA sections. > > > > ### Second Attempt > > > > I set `cdata-section-elements` in the XQuery. > > > > rss.xq: > > ``` > > xquery version "3.0"; > > declare namespace content = "http://purl.org/rss/1.0/modules/content/"; > > declare option output:omit-xml-declaration "no"; > > declare option output:cdata-section-elements "content:encoded"; > > > > let $in := > > <root> > > <child>hello</child> > > </root> > > let $style := doc( 'rss.xslt' ) > > return xslt:transform( $in, $style ) > > ``` > > > > rss.xslt: > > [Unchanged] > > > > Result: > > [XPST0081] No namespace declared for 'content:encoded'. > > > > Clearly I declared the namespace two lines up. > > > > This looks like a bug to me, but any help appreciated if I’ve missed a > > step here. > > > > Thanks, > > Hugh > >
HG
Hugh Guiney1 Aug 2018 23:17 #
Hello, First off, loving BaseX so far! Using it as the backend for an API I’m building. However, I’m running into an issue. I’m trying to transform my database XML into an RSS 2.0 feed. It’s mostly working fine, but I can’t output CDATA content at all, which I need to do for content:encoded elements. Specs: - BaseX 9.0.2 (started via basexserver script) - Saxon-HE 9.8.0.12J from Saxonica - java version "1.8.0_112" - basex 0.9.0 (NodeJS) - macOS Sierra 10.12.6 ### First Attempt I set cdata-section-elements in the XSLT. rss.xq:
xquery version "3.0";
declare option output:omit-xml-declaration "no";

let $in :=
  <root>
    <child>hello</child>
  </root>
let $style := doc( 'rss.xslt' )
return xslt:transform( $in, $style )
rss.xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform
  version="3.0"
  xmlns="http://backend.userland.com/rss2"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
>
  <xsl:output
    omit-xml-declaration="no"
    cdata-section-elements="content:encoded"
  />
  <xsl:template match="/">
    <rss version="2.0">
      <content:encoded>hi</content:encoded>
      <content:encoded><xsl:text>howdy</xsl:text></content:encoded>
      <content:encoded><xsl:value-of select="//child" /></content:encoded>
    </rss>
  </xsl:template>
</xsl:transform>
Result:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns="http://backend.userland.com/rss2"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
version="2.0">
  <content:encoded>hi</content:encoded>
  <content:encoded>howdy</content:encoded>
  <content:encoded>hello</content:encoded>
</rss>
No CDATA sections. ### Second Attempt I set cdata-section-elements in the XQuery. rss.xq:
xquery version "3.0";
declare namespace content = "http://purl.org/rss/1.0/modules/content/";
declare option output:omit-xml-declaration "no";
declare option output:cdata-section-elements "content:encoded";

let $in :=
  <root>
    <child>hello</child>
  </root>
let $style := doc( 'rss.xslt' )
return xslt:transform( $in, $style )
rss.xslt: [Unchanged] Result: [XPST0081] No namespace declared for 'content:encoded'. Clearly I declared the namespace two lines up. This looks like a bug to me, but any help appreciated if I’ve missed a step here. Thanks, Hugh
HG
Hugh Guineyin reply to Imsieke, Gerrit, le-tex, 1 Aug 2018, 21:502 Aug 2018 01:48 #
Thanks for testing Gerrit, that's good to know. Sounds like a regression then. Shall I go ahead and file this on Github or does it need further confirmation? Christian, your suggestion seems to work around the issue; the CDATA sections do come in that way. Except, all the elements get sent back entity-escaped for some reason. I have to manually reverse it back into XML using result.replace( /&gt;/gi, '>' ).replace( /&lt;/gi, '<' ) in JavaScript. Not sure if that is a separate issue or expected behavior.
Quoted text · le-tex · 136 lines
On Wed, Aug 1, 2018 at 2:50 PM, Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de> wrote: > Hi Hugh, > > The second version where you specify the serialization options in XQuery > works for me (BaseX GUI 8.6.5 with Saxon PE 9.6.0.7): > > <?xml version="1.0" encoding="UTF-8"?> > <rss xmlns="http://backend.userland.com/rss2" > xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> > <content:encoded><![CDATA[hi]]></content:encoded> > <content:encoded><![CDATA[howdy]]></content:encoded> > <content:encoded/> > </rss> > > The first version cannot generate CDATA sections since the XSLT processor is > not serializing anything; it’s the XQuery processor that serializes the > result. > > The error that you are seeing, XPST0081, would be generated if there were no > namespace declaration for the prefix 'content', maybe caused by an > indistinguishable look-alike non-ASCII character in 'content'. Doesn’t seem > to be the case. Maybe this is a bug that is specific to BaseX 9? > > Gerrit > > > > On 01.08.2018 21:17, Hugh Guiney wrote: >> >> Hello, >> >> First off, loving BaseX so far! Using it as the backend for an API I’m >> building. However, I’m running into an issue. I’m trying to transform >> my database XML into an RSS 2.0 feed. It’s mostly working fine, but I >> can’t output CDATA content at all, which I need to do for >> `content:encoded` elements. >> >> Specs: >> >> - BaseX 9.0.2 (started via basexserver script) >> - Saxon-HE 9.8.0.12J from Saxonica >> - java version "1.8.0_112" >> - basex 0.9.0 (NodeJS) >> - macOS Sierra 10.12.6 >> >> ### First Attempt >> >> I set `cdata-section-elements` in the XSLT. >> >> rss.xq: >> ``` >> xquery version "3.0"; >> declare option output:omit-xml-declaration "no"; >> >> let $in := >> <root> >> <child>hello</child> >> </root> >> let $style := doc( 'rss.xslt' ) >> return xslt:transform( $in, $style ) >> ``` >> >> rss.xslt: >> ``` >> <?xml version="1.0" encoding="UTF-8"?> >> <xsl:transform >> version="3.0" >> xmlns="http://backend.userland.com/rss2" >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >> xmlns:content="http://purl.org/rss/1.0/modules/content/" >>> >>> >> <xsl:output >> omit-xml-declaration="no" >> cdata-section-elements="content:encoded" >> /> >> <xsl:template match="/"> >> <rss version="2.0"> >> <content:encoded>hi</content:encoded> >> <content:encoded><xsl:text>howdy</xsl:text></content:encoded> >> <content:encoded><xsl:value-of select="//child" >> /></content:encoded> >> </rss> >> </xsl:template> >> </xsl:transform> >> ``` >> >> Result: >> ``` >> <?xml version="1.0" encoding="UTF-8"?> >> <rss xmlns="http://backend.userland.com/rss2" >> xmlns:content="http://purl.org/rss/1.0/modules/content/" >> version="2.0"> >> <content:encoded>hi</content:encoded> >> <content:encoded>howdy</content:encoded> >> <content:encoded>hello</content:encoded> >> </rss> >> ``` >> >> No CDATA sections. >> >> ### Second Attempt >> >> I set `cdata-section-elements` in the XQuery. >> >> rss.xq: >> ``` >> xquery version "3.0"; >> declare namespace content = "http://purl.org/rss/1.0/modules/content/"; >> declare option output:omit-xml-declaration "no"; >> declare option output:cdata-section-elements "content:encoded"; >> >> let $in := >> <root> >> <child>hello</child> >> </root> >> let $style := doc( 'rss.xslt' ) >> return xslt:transform( $in, $style ) >> ``` >> >> rss.xslt: >> [Unchanged] >> >> Result: >> [XPST0081] No namespace declared for 'content:encoded'. >> >> Clearly I declared the namespace two lines up. >> >> This looks like a bug to me, but any help appreciated if I’ve missed a >> step here. >> >> Thanks, >> Hugh >> >
LV
Lizzi, Vincent2 Aug 2018 04:57 #
Hugh, As Gerrit mentioned, the issue you have encountered is due to the xslt:transform function returning, essentially, a parsed XML document, so the serialization controls that are declared in the XSLT are not being used. If you want the serialized output of the XSLT you can use the xslt:transform-text function. For example:
let $in := <root><child>hello</child></root>

let $xslt := doc('rss.xslt')

let $out := xslt:transform-text($in, $xslt)
Quoted text · BaseX-Talk · 150 lines
From: BaseX-Talk <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of Hugh Guiney <hugh.guiney at gmail.com> Sent: Wednesday, August 1, 2018 5:47:55 PM To: Imsieke, Gerrit, le-tex Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Can't get `cdata-section-elements` to work at all for XSLT output Thanks for testing Gerrit, that's good to know. Sounds like a regression then. Shall I go ahead and file this on Github or does it need further confirmation? Christian, your suggestion seems to work around the issue; the CDATA sections do come in that way. Except, all the elements get sent back entity-escaped for some reason. I have to manually reverse it back into XML using `result.replace( />/gi, '>' ).replace( /</gi, '<' )` in JavaScript. Not sure if that is a separate issue or expected behavior. On Wed, Aug 1, 2018 at 2:50 PM, Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de> wrote: > Hi Hugh, > > The second version where you specify the serialization options in XQuery > works for me (BaseX GUI 8.6.5 with Saxon PE 9.6.0.7<http://9.6.0.7>: > > <?xml version="1.0" encoding="UTF-8"?> > <rss xmlns="http://backend.userland.com/rss2<http://backend.userland.com/rss2>" > xmlns:content="http://purl.org/rss/1.0/modules/content/<http://purl.org/rss/1.0/modules/content/>" version="2.0"> > <content:encoded><![CDATA[hi]]></content:encoded> > <content:encoded><![CDATA[howdy]]></content:encoded> > <content:encoded/> > </rss> > > The first version cannot generate CDATA sections since the XSLT processor is > not serializing anything; it’s the XQuery processor that serializes the > result. > > The error that you are seeing, XPST0081, would be generated if there were no > namespace declaration for the prefix 'content', maybe caused by an > indistinguishable look-alike non-ASCII character in 'content'. Doesn’t seem > to be the case. Maybe this is a bug that is specific to BaseX 9? > > Gerrit > > > > On 01.08.2018 21:17, Hugh Guiney wrote: >> >> Hello, >> >> First off, loving BaseX so far! Using it as the backend for an API I’m >> building. However, I’m running into an issue. I’m trying to transform >> my database XML into an RSS 2.0 feed. It’s mostly working fine, but I >> can’t output CDATA content at all, which I need to do for >> `content:encoded` elements. >> >> Specs: >> >> - BaseX 9.0.2 (started via basexserver script) >> - Saxon-HE 9.8.0.12J from Saxonica >> - java version "1.8.0_112" >> - basex 0.9.0 (NodeJS) >> - macOS Sierra 10.12.6 >> >> ### First Attempt >> >> I set `cdata-section-elements` in the XSLT. >> >> rss.xq: >> ``` >> xquery version "3.0"; >> declare option output:omit-xml-declaration "no"; >> >> let $in := >> <root> >> <child>hello</child> >> </root> >> let $style := doc( 'rss.xslt' ) >> return xslt:transform( $in, $style ) >> ``` >> >> rss.xslt: >> ``` >> <?xml version="1.0" encoding="UTF-8"?> >> <xsl:transform >> version="3.0" >> xmlns="http://backend.userland.com/rss2<http://backend.userland.com/rss2>" >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform<http://www.w3.org/1999/XSL/Transform>" >> xmlns:content="http://purl.org/rss/1.0/modules/content/<http://purl.org/rss/1.0/modules/content/>" >>> >>> >> <xsl:output >> omit-xml-declaration="no" >> cdata-section-elements="content:encoded" >> /> >> <xsl:template match="/"> >> <rss version="2.0"> >> <content:encoded>hi</content:encoded> >> <content:encoded><xsl:text>howdy</xsl:text></content:encoded> >> <content:encoded><xsl:value-of select="//child" >> /></content:encoded> >> </rss> >> </xsl:template> >> </xsl:transform> >> ``` >> >> Result: >> ``` >> <?xml version="1.0" encoding="UTF-8"?> >> <rss xmlns="http://backend.userland.com/rss2<http://backend.userland.com/rss2>" >> xmlns:content="http://purl.org/rss/1.0/modules/content/<http://purl.org/rss/1.0/modules/content/>" >> version="2.0"> >> <content:encoded>hi</content:encoded> >> <content:encoded>howdy</content:encoded> >> <content:encoded>hello</content:encoded> >> </rss> >> ``` >> >> No CDATA sections. >> >> ### Second Attempt >> >> I set `cdata-section-elements` in the XQuery. >> >> rss.xq: >> ``` >> xquery version "3.0"; >> declare namespace content = "http://purl.org/rss/1.0/modules/content/<http://purl.org/rss/1.0/modules/content/>"; >> declare option output:omit-xml-declaration "no"; >> declare option output:cdata-section-elements "content:encoded"; >> >> let $in := >> <root> >> <child>hello</child> >> </root> >> let $style := doc( 'rss.xslt' ) >> return xslt:transform( $in, $style ) >> ``` >> >> rss.xslt: >> [Unchanged] >> >> Result: >> [XPST0081] No namespace declared for 'content:encoded'. >> >> Clearly I declared the namespace two lines up. >> >> This looks like a bug to me, but any help appreciated if I’ve missed a >> step here. >> >> Thanks, >> Hugh >> >
CG
Christian Grünin reply to Hugh Guiney, 2 Aug 2018, 10:172 Aug 2018 08:59 #
Hi Hugh,
Quoted text · Hugh Guiney · 2 lines
> I understand, but did you see the details of my second attempt? The > serialization controls didn’t work when specified in XQuery either.
I don’t get XPST0081 for this query (as indicated in a previous reply of mine). Could you please clarify first if the unchanged query you supplied via your first mail really fails on your machine? If no (i.e., if it runs successfully with the declared namespace), please give us more details on how to trigger this behavior. I get the following result with both 9.0.2 and 9.1 beta when running the query of your second attempt in the BaseX GUI or on command line:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns="http://backend.userland.com/rss2"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
version="2.0">
  <content:encoded><![CDATA[hi]]></content:encoded>
  <content:encoded><![CDATA[howdy]]></content:encoded>
  <content:encoded><![CDATA[hello]]></content:encoded>
</rss>
Could you please try what result you get if you run the query directly in the GUI or on command-line? If the result is correct, we can proceed further. If it’s already wrong, we may need to compare our BaseX configurations (in that case, we should start with a newly downloaded instance of one of our distributions). And if the problem persists, maybe we could even simplify your example and try the following query:
  declare option output:cdata-section-elements "xml";
  <xml>A</xml>
Does it yield different results with BaseX 8 and 9 on your machine?
Quoted text · Hugh Guiney · 2 lines
> And why do the same serialization options in XQuery work > in BaseX 8 but not BaseX 9?
Just to be sure: Is this already a fact (did you compare the versions by yourself), or is it still a guess?
Quoted text · Hugh Guiney · 2 lines
> why would I want the result to come > back as an escaped string instead of real nodes?
Same here: With xquery:transform-text, or with Vincent’s query, nothing will be escaped on my machine. The result is pretty similar to the result of your second attempt, it’s only the indentation that differs slightly. Best, Christian
IL
Imsieke, Gerrit, le-texin reply to Hugh Guiney, 2 Aug 2018, 01:482 Aug 2018 09:04 #
Hi Hugh, Did you see Christian’s reply, archived at https://mailman.uni-konstanz.de/pipermail/basex-talk/2018-August/013490.html⁠? He essentially said that, for your second approach, he saw the same behavior on BaseX 9.x as I saw on 8.6.5. So there doesn’t seem to be a regression. I agree with you that xslt:transform-text() is not a solution. Gerrit
Quoted text · Hugh Guiney · 148 lines
On 01.08.2018 23:47, Hugh Guiney wrote: > Thanks for testing Gerrit, that's good to know. Sounds like a > regression then. Shall I go ahead and file this on Github or does it > need further confirmation? > > Christian, your suggestion seems to work around the issue; the CDATA > sections do come in that way. Except, all the elements get sent back > entity-escaped for some reason. I have to manually reverse it back > into XML using `result.replace( /&gt;/gi, '>' ).replace( /&lt;/gi, '<' > )` in JavaScript. Not sure if that is a separate issue or expected > behavior. > > On Wed, Aug 1, 2018 at 2:50 PM, Imsieke, Gerrit, le-tex > <gerrit.imsieke at le-tex.de> wrote: >> Hi Hugh, >> >> The second version where you specify the serialization options in XQuery >> works for me (BaseX GUI 8.6.5 with Saxon PE 9.6.0.7): >> >> <?xml version="1.0" encoding="UTF-8"?> >> <rss xmlns="http://backend.userland.com/rss2" >> xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> >> <content:encoded><![CDATA[hi]]></content:encoded> >> <content:encoded><![CDATA[howdy]]></content:encoded> >> <content:encoded/> >> </rss> >> >> The first version cannot generate CDATA sections since the XSLT processor is >> not serializing anything; it’s the XQuery processor that serializes the >> result. >> >> The error that you are seeing, XPST0081, would be generated if there were no >> namespace declaration for the prefix 'content', maybe caused by an >> indistinguishable look-alike non-ASCII character in 'content'. Doesn’t seem >> to be the case. Maybe this is a bug that is specific to BaseX 9? >> >> Gerrit >> >> >> >> On 01.08.2018 21:17, Hugh Guiney wrote: >>> >>> Hello, >>> >>> First off, loving BaseX so far! Using it as the backend for an API I’m >>> building. However, I’m running into an issue. I’m trying to transform >>> my database XML into an RSS 2.0 feed. It’s mostly working fine, but I >>> can’t output CDATA content at all, which I need to do for >>> `content:encoded` elements. >>> >>> Specs: >>> >>> - BaseX 9.0.2 (started via basexserver script) >>> - Saxon-HE 9.8.0.12J from Saxonica >>> - java version "1.8.0_112" >>> - basex 0.9.0 (NodeJS) >>> - macOS Sierra 10.12.6 >>> >>> ### First Attempt >>> >>> I set `cdata-section-elements` in the XSLT. >>> >>> rss.xq: >>> ``` >>> xquery version "3.0"; >>> declare option output:omit-xml-declaration "no"; >>> >>> let $in := >>> <root> >>> <child>hello</child> >>> </root> >>> let $style := doc( 'rss.xslt' ) >>> return xslt:transform( $in, $style ) >>> ``` >>> >>> rss.xslt: >>> ``` >>> <?xml version="1.0" encoding="UTF-8"?> >>> <xsl:transform >>> version="3.0" >>> xmlns="http://backend.userland.com/rss2" >>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >>> xmlns:content="http://purl.org/rss/1.0/modules/content/" >>>> >>>> >>> <xsl:output >>> omit-xml-declaration="no" >>> cdata-section-elements="content:encoded" >>> /> >>> <xsl:template match="/"> >>> <rss version="2.0"> >>> <content:encoded>hi</content:encoded> >>> <content:encoded><xsl:text>howdy</xsl:text></content:encoded> >>> <content:encoded><xsl:value-of select="//child" >>> /></content:encoded> >>> </rss> >>> </xsl:template> >>> </xsl:transform> >>> ``` >>> >>> Result: >>> ``` >>> <?xml version="1.0" encoding="UTF-8"?> >>> <rss xmlns="http://backend.userland.com/rss2" >>> xmlns:content="http://purl.org/rss/1.0/modules/content/" >>> version="2.0"> >>> <content:encoded>hi</content:encoded> >>> <content:encoded>howdy</content:encoded> >>> <content:encoded>hello</content:encoded> >>> </rss> >>> ``` >>> >>> No CDATA sections. >>> >>> ### Second Attempt >>> >>> I set `cdata-section-elements` in the XQuery. >>> >>> rss.xq: >>> ``` >>> xquery version "3.0"; >>> declare namespace content = "http://purl.org/rss/1.0/modules/content/"; >>> declare option output:omit-xml-declaration "no"; >>> declare option output:cdata-section-elements "content:encoded"; >>> >>> let $in := >>> <root> >>> <child>hello</child> >>> </root> >>> let $style := doc( 'rss.xslt' ) >>> return xslt:transform( $in, $style ) >>> ``` >>> >>> rss.xslt: >>> [Unchanged] >>> >>> Result: >>> [XPST0081] No namespace declared for 'content:encoded'. >>> >>> Clearly I declared the namespace two lines up. >>> >>> This looks like a bug to me, but any help appreciated if I’ve missed a >>> step here. >>> >>> Thanks, >>> Hugh >>> >>
-- Gerrit Imsieke Geschäftsführer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke at le-tex.de, http://www.le-tex.de Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930 Geschäftsführer / Managing Directors: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
HG
Hugh Guineyin reply to Lizzi, Vincent, 2 Aug 2018, 04:572 Aug 2018 10:17 #
Hi Vincent, I understand, but did you see the details of my second attempt? The serialization controls didn’t work when specified in XQuery either. Which they should have, right? I mean, why else would BaseX provide XSLT options like output:omit-xml-declaration if you’re not supposed to use them? And why do the same serialization options in XQuery work in BaseX 8 but not BaseX 9? If I was to do further manipulation of the XSLT output in XQuery instead of just immediately sending it to the browser or saving it to a file, why would I want the result to come back as an escaped string instead of real nodes? My first attempt may have been the wrong approach for what I wanted to do—in which case I would suggest a note in the documentation, since it isn’t obvious compared to the usual method of specifying xsl:output—but my second attempt gives me an error for “not declaring a namespace” that I have clearly declared. That seems like a bug, no? - Hugh
Quoted text · Vincent · 194 lines
On Wed, Aug 1, 2018 at 9:57 PM, Lizzi, Vincent <Vincent.Lizzi at taylorandfrancis.com> wrote: > Hugh, > > > As Gerrit mentioned, the issue you have encountered is due to the > xslt:transform function returning, essentially, a parsed XML document, so > the serialization controls that are declared in the XSLT are not being used. > If you want the serialized output of the XSLT you can use the > xslt:transform-text function. For example: > > > let $in := <root><child>hello</child></root> > > let $xslt := doc('rss.xslt') > > let $out := xslt:transform-text($in, $xslt) > > return file:write-text('out.xml', $out) > > > I hope this helps. > > > Vincent > > > http://docs.basex.org/wiki/XSLT_Module#xslt:transform-text > > http://docs.basex.org/wiki/File_Module#file:write-text > > > > > ________________________________ > From: BaseX-Talk <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of > Hugh Guiney <hugh.guiney at gmail.com> > Sent: Wednesday, August 1, 2018 5:47:55 PM > To: Imsieke, Gerrit, le-tex > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] Can't get `cdata-section-elements` to work at all > for XSLT output > > Thanks for testing Gerrit, that's good to know. Sounds like a > regression then. Shall I go ahead and file this on Github or does it > need further confirmation? > > Christian, your suggestion seems to work around the issue; the CDATA > sections do come in that way. Except, all the elements get sent back > entity-escaped for some reason. I have to manually reverse it back > into XML using `result.replace( />/gi, '>' ).replace( /</gi, '<' > )` in JavaScript. Not sure if that is a separate issue or expected > behavior. > > On Wed, Aug 1, 2018 at 2:50 PM, Imsieke, Gerrit, le-tex > <gerrit.imsieke at le-tex.de> wrote: >> Hi Hugh, >> >> The second version where you specify the serialization options in XQuery >> works for me (BaseX GUI 8.6.5 with Saxon PE 9.6.0.7: > >> >> <?xml version="1.0" encoding="UTF-8"?> >> <rss xmlns="http://backend.userland.com/rss2" >> xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> >> <content:encoded><![CDATA[hi]]></content:encoded> >> <content:encoded><![CDATA[howdy]]></content:encoded> >> <content:encoded/> >> </rss> >> >> The first version cannot generate CDATA sections since the XSLT processor >> is >> not serializing anything; it’s the XQuery processor that serializes the >> result. >> >> The error that you are seeing, XPST0081, would be generated if there were >> no >> namespace declaration for the prefix 'content', maybe caused by an >> indistinguishable look-alike non-ASCII character in 'content'. Doesn’t >> seem >> to be the case. Maybe this is a bug that is specific to BaseX 9? >> >> Gerrit >> >> >> >> On 01.08.2018 21:17, Hugh Guiney wrote: >>> >>> Hello, >>> >>> First off, loving BaseX so far! Using it as the backend for an API I’m >>> building. However, I’m running into an issue. I’m trying to transform >>> my database XML into an RSS 2.0 feed. It’s mostly working fine, but I >>> can’t output CDATA content at all, which I need to do for >>> `content:encoded` elements. >>> >>> Specs: >>> >>> - BaseX 9.0.2 (started via basexserver script) >>> - Saxon-HE 9.8.0.12J from Saxonica >>> - java version "1.8.0_112" >>> - basex 0.9.0 (NodeJS) >>> - macOS Sierra 10.12.6 >>> >>> ### First Attempt >>> >>> I set `cdata-section-elements` in the XSLT. >>> >>> rss.xq: >>> ``` >>> xquery version "3.0"; >>> declare option output:omit-xml-declaration "no"; >>> >>> let $in := >>> <root> >>> <child>hello</child> >>> </root> >>> let $style := doc( 'rss.xslt' ) >>> return xslt:transform( $in, $style ) >>> ``` >>> >>> rss.xslt: >>> ``` >>> <?xml version="1.0" encoding="UTF-8"?> >>> <xsl:transform >>> version="3.0" >>> xmlns="http://backend.userland.com/rss2" >>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >>> xmlns:content="http://purl.org/rss/1.0/modules/content/" >>>> >>>> >>> <xsl:output >>> omit-xml-declaration="no" >>> cdata-section-elements="content:encoded" >>> /> >>> <xsl:template match="/"> >>> <rss version="2.0"> >>> <content:encoded>hi</content:encoded> >>> <content:encoded><xsl:text>howdy</xsl:text></content:encoded> >>> <content:encoded><xsl:value-of select="//child" >>> /></content:encoded> >>> </rss> >>> </xsl:template> >>> </xsl:transform> >>> ``` >>> >>> Result: >>> ``` >>> <?xml version="1.0" encoding="UTF-8"?> >>> <rss xmlns="http://backend.userland.com/rss2" >>> xmlns:content="http://purl.org/rss/1.0/modules/content/" >>> version="2.0"> >>> <content:encoded>hi</content:encoded> >>> <content:encoded>howdy</content:encoded> >>> <content:encoded>hello</content:encoded> >>> </rss> >>> ``` >>> >>> No CDATA sections. >>> >>> ### Second Attempt >>> >>> I set `cdata-section-elements` in the XQuery. >>> >>> rss.xq: >>> ``` >>> xquery version "3.0"; >>> declare namespace content = "http://purl.org/rss/1.0/modules/content/"; >>> declare option output:omit-xml-declaration "no"; >>> declare option output:cdata-section-elements "content:encoded"; >>> >>> let $in := >>> <root> >>> <child>hello</child> >>> </root> >>> let $style := doc( 'rss.xslt' ) >>> return xslt:transform( $in, $style ) >>> ``` >>> >>> rss.xslt: >>> [Unchanged] >>> >>> Result: >>> [XPST0081] No namespace declared for 'content:encoded'. >>> >>> Clearly I declared the namespace two lines up. >>> >>> This looks like a bug to me, but any help appreciated if I’ve missed a >>> step here. >>> >>> Thanks, >>> Hugh >>> >>

⚡Generated with XQuery