1

I am trying to figure out if I am declaring my DTD elements correctly in an xml document. From everything I can tell, neither xsltproc or xmllint detect the validity errors in the following document:

<!DOCTYPE basic-dtd [
        <!ENTITY title "The Book of Love">
        <!ENTITY author "Jeffrey Halcomb">

        <!ELEMENT basic-dtd (title,author,subject,checked-out)>                                                                                                                   
        <!ELEMENT title (#PCDATA)>
        <!ELEMENT author (#PCDATA)>
        <!ELEMENT checked-out EMPTY>
]>

<basic-dtd>
        <author>&author;</author>
        <title>&title;</title>
        <subject>A treatise on love as a driving elemental force in nature</subject>
        <checked-out>Yes</checked-out>
</basic-dtd>

In my doctype instruction, I (believe) I have specified:

  • the correct order of elements in the basic-dtd element is title, author, subject, and checked-out.
  • the element 'checked-out' should not contain any data (PCDATA,CDATA, or child elements)

And yet, when I run the following stylesheet against this xml (xsltproc basic-dtd.xsl basic-dtd.xml) , it reports no errors/warnings.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >                                                                                                  
        <xsl:output omit-xml-declaration="no" indent="yes"/>
        <xsl:strip-space elements="*"/>
        <xsl:template match="/basic-dtd">
          <xsl:copy-of select="."/>
        </xsl:template>
</xsl:stylesheet>

Likewise, when I run xmllint (xmllint --noent basic-dtd.xml) - it reports no errors.

xsltproc and xmllint (with --noent) do process the entities, and will error out if an unknown entity is used.

Am I using an apple-processor to transform/print orange-xml (wrong tool for the job), or is this a known feature?

Thanks,

Tom

4
  • I don't remember xsltproc doing validation. Did you try the --valid command line arg with xmllint? Commented Apr 6, 2020 at 16:59
  • YEAH!!! Thank-you! That did the trick. I think its interesting that one can use DTDs in stylesheets, schemas, etc... just to a limited extent: - adding default/fixed values to elements, and - using entities to create xsl:params/text in the output. Commented Apr 6, 2020 at 17:17
  • There's always the option of schema-aware XSLT processors like Saxon PE/HE. Commented Apr 6, 2020 at 18:46
  • Added my comments as an answer. Commented Apr 7, 2020 at 17:05

1 Answer 1

1

I don't remember xsltproc doing validation.

Try using the --valid command line arg with xmllint.

There's also the option of using a schema/dtd-aware XSLT processor like Saxon PE/HE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.