XSL - testing if a document is valid

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

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



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".

Thanks
Radu
Posts: 5207

Re: XSL - testing if a document is valid

Tue Sep 20, 2016 9:46 am

Hi,

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

https://www.w3.org/TR/xpath-functions/#func-doc-available

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 2 guests