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'.
On Wed, Aug 1, 2018 at 9:50 PM Imsieke, Gerrit, le-tex gerrit.imsieke@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