FondDuLac
FondDuLac

Reputation: 21

In Marklogic (5.x), how can I include a doctype declaration in a zipped document?

I have a document that I run through an xslt and then capture in a variable, e.g. $doc.

The xslt has the requisite output options set so that I can get my docytpe declaration prolog in the document, and when I do an xdmp:save with $doc, reiterating the output settings in the save options node (but is that necessary?), I happily get my doctype declaration, as specified in my <xsl:output/> options.

However, I would like to zip up the document that I get together with other, binary documents, and save that.

But the the zipped up document, does not contain my doctype declaration.

I create the zip via a function in a module that has the requisitie xdmp:output options set as for the xslt, but MarkLogic/Xquery-style. And my zip function is like so:

`declare function p2n:bundle-document($basename as xs:string, $doc as document-node()) as binary()
{
  let $manifest := <parts xmlns="xdmp:zip">
                    {
                      <part>{$basename}</part>
                    }
                   </parts>
 let $zip       := xdmp:zip-create($manifest, $doc)
 return $zip  
};`

To no avail, alas. When I finally open up the zip, and there is no DOCTYPE declaration.

Thank you,

Upvotes: 1

Views: 232

Answers (1)

grtjn
grtjn

Reputation: 20414

You need to apply xdmp:quote, and wrap the result in a text node to do this, for example like this:

let $basename := "test.xml"
let $xsl :=
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

        <xsl:output doctype-public="test" doctype-system="test"/>

        <xsl:template match="@*|node()">
            <xsl:copy-of select="."/>
        </xsl:template> 
    </xsl:stylesheet>

let $xml := <test/>
let $doc := text { xdmp:quote(xdmp:xslt-eval($xsl, $xml))}
let $manifest :=
    <parts xmlns="xdmp:zip">{
        <part>{$basename}</part>
    }</parts>
let $zip := xdmp:zip-create($manifest, $doc)
return
    xdmp:save("d:\tmp\test.zip", $zip) 

HTH!

Upvotes: 1

Related Questions