Home > Blockchain >  How to access XML declaration part using XSLT
How to access XML declaration part using XSLT

Time:07-26

I want to validate some conditions in the declaration part of the XML using XSLT.

<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with MathML3 v1.1d1 20130915//EN" "JATS-archivearticle1-mathml3.dtd">

and

<?xml version="1.0" encoding="UTF-8"?>

The validations are

  1. To ensure "<!DOCTYPE" and "<?xml " declaration are exactly present or not
  2. To ensure DTD version "JATS-archivearticle1-mathml3.dtd" mentioned in it

Is there any code in XSLT?

CodePudding user response:

Andrew Welch's lexev tool was designed for this kind of task - see https://ajwelch.blogspot.com/2008/08/lexev-xmlreader-converts-lexical-events.html I haven't heard of it for a while and I don't know if it's still operational.

CodePudding user response:

I am pretty sure you can't do this in XSLT 2.0.

See the "Parsing and Serialization" section of the XSLT 2.0 specification:

Users should be aware, however, that since the input to the transformation is a tree conforming to the XDM data model as described in [Data Model], constructs that might exist in the original XML document, or in the DOM, but which are not within the scope of the data model, cannot be processed by the stylesheet and cannot be guaranteed to remain unchanged in the transformation output. Such constructs include CDATA section boundaries, the use of entity references, and the DOCTYPE declaration and internal DTD subset.

In XSLT 3.0 you could try reading the file as text, using the unparsed-text-lines() XPath function, and validating the first couple of lines using regular expressions.

  • Related