XSL - testing if a document is valid

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
Posts: 51

XSL - testing if a document is valid

Tue Sep 20, 2016 7:13 am

I'm processing a number of files using an XSL document and I've discovered that a few of the files are not valid. When open them (using the document() function) I get the following error message and transform stops:

Code: Select all

Severity: fatal
Description: Premature end of file.
URL: http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/trans/SaxonErrorCode.html#SXXP0003

Here's a snippet of the xslt code that I'm working with:

Code: Select all

  <xsl:when test="contains(@filetype, 'ISHIllustration')">
    <xsl:attribute name="doctype">illustration</xsl:attribute>
    <xsl:variable name="filePathFull">
      <xsl:text>file:/</xsl:text><xsl:value-of select="$basePath"/>/<xsl:value-of select="$filePath"/>
    <xsl:attribute name="doctype" select="document($filePathFull)/name(/*)"/>

Is there a way to test for a valid XML file and continue if OK, but skip the file if it's not valid?
Specifically, I'd have the transform to use the valid value for @doctype, but when an error is found use @doctype="unknown".

Posts: 5376

Re: XSL - testing if a document is valid

Tue Sep 20, 2016 9:46 am


Maybe you should try to use the doc-available function, it should return "false" if the XML is not wellformed:


Radu Coravu
<oXygen/> XML Editor

Return to “Common Problems”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 7 guests