Requirement: Is to add correct Doctype declaration on the output xml [The root element of the input xml can be chapter or section element]
Input XML: chapter.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookx.dtd">
<chapter>
<title>Chapter Template Title</title>
<para>Text</para>
<section>
<title>Section Title</title>
<para>Section text</para>
</section>
</chapter>
XSLT file: test.xsl:
- Stylesheet just copies input xml to output and adds @sec on all element
Stylesheet adds correct doctype declaration to output xml, because the input xml root element can be <chapter> or <section> element
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template name="add-doctype-declaration"> <xsl:choose> <xsl:when test="/chapter"> <xsl:text disable-output-escaping="yes"> <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookx.dtd"> </xsl:text> </xsl:when> <xsl:when test="/section"> <xsl:text disable-output-escaping="yes"> <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookx.dtd"> </xsl:text> </xsl:when> </xsl:choose> </xsl:template> <xsl:template match="/"> <xsl:call-template name="add-doctype-declaration"/> <xsl:apply-templates/> </xsl:template> <!-- Identity Template --> <xsl:template match="@*|*|processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="section"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:attribute name="sec"> <xsl:number/> </xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Expected output.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookx.dtd">
<chapter>
<title>Chapter Template Title</title>
<para>Text</para>
<section sec="1">
<title>Section Title</title>
<para>Section text</para>
</section>
</chapter>
Using any XSLT engine, the transformation works absolutely fine, and able to get the expected output
But, if the transformation is done through XProc I end up with the following error. Can someone help in resolving this error
err:XD0001 : XD0001 It is a dynamic error if a non-XML resource is produced on a step output or arrives on a step input.
XProc file: test.xpl
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0" name="testing">
<p:input port="source">
<p:document href="chapter.xml"/>
</p:input>
<p:output port="result">
<p:empty/>
</p:output>
<p:xslt version="1.0" name="transform">
<p:input port="stylesheet">
<p:document href="test.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:store omit-xml-declaration="false" encoding="utf-8" name="serialize">
<p:with-option name="href" select="output.xml"/>
</p:store>
</p:declare-step>