Page 1 of 1

Can I save the DOCTYPE declaration to a variable?

Posted: Thu Oct 24, 2019 2:33 am
by mboudreau
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?

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

Posted: Thu Oct 24, 2019 7:45 am
by Radu
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