How to read doctype declaration of an xml using xslt?

59 Views Asked by At

Is there a way to read the doctype declaration of an xml using xslt?

Example XML doctype declaration:

<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables with MathML3 v1.1 20151215//EN" "JATS-archive-oasis-article1-mathml3.dtd">

I need to check if the doctype declaration contains the specific dtd mention above if the condition is true then I need to generate an element in my xml output.

I tried unparsed-text-lines() and unparsed-text(). Locally it working by supplying the uri of the xml file but in pipeline its not.

Is there a way to read those?

I found saxon:schema function but not sure how use it or if its for xml and xsd combination only not for xml and dtd thing.

https://www.saxonica.com/html/documentation11/functions/saxon/schema.html

1

There are 1 best solutions below

0
Michael Kay On

The DOCTYPE declaration is not part of the XDM data model, which means it's not part of the document that can be accessed using standard XSLT/XPath constructs.

As Martin points out, it is made available to SAX applications (specifically, by notifying startDTD and endDTD to the LexicalHandler). You could exploit this by writing a SAX filter that converts the DOCTYPE declaration to a suitable processing instruction. Your URIResolver could return a SAXSource that incorporates this filter; the DOCTYPE declaration would then be accessible to the XSLT code as a processing instruction child of the document (root) node.