Can I save the DOCTYPE declaration to a variable?

Here should go questions about transforming XML with XSLT and FOP.
mboudreau
Posts: 48
Joined: Sat Jan 07, 2017 1:23 am

Can I save the DOCTYPE declaration to a variable?

Post by mboudreau » Thu Oct 24, 2019 2:33 am

I'd like to write a single XSL transformation that can process instances of different (but similar) doctypes. I also want to include the input doctype declaration in the output, so I can't write specific values into an <xsl:output> element.

Is there a way to capture the content of the doctype declaration in a variable, which I could then output between the XML declaration and the root element?

Radu
Posts: 6922
Joined: Fri Jul 09, 2004 5:18 pm

Re: Can I save the DOCTYPE declaration to a variable?

Post by Radu » Thu Oct 24, 2019 7:45 am

Hi,

The original DOCTYPE declaration is not accessible to the XSLT stylesheet.
What we do for our Oxygen custom XSLT-based refactoring operations:

https://www.oxygenxml.com/doc/versions/ ... tools.html

is that we extract the DOCTYPE declaration separately using Java code, then apply the XSLT over the XML which no longer has the DOCTYPE and then assemble the DOCTYPE back later on.

Another approach is to have some kind of pre-processing which applies a regular expression on each file so that the DOCTYPE declaration is replaced by an equivalent XML comment, then apply the XSLT then convert the XML comment back to a DOCTYPE by applying another regexp, like in this small ANT build file:

https://github.com/oxygenxml/dita-refac ... /build.xml

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply