XSL - testing if a document is valid
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 72
- Joined: Tue Oct 21, 2014 10:01 pm
XSL - testing if a document is valid
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:
Here's a snippet of the xslt code that I'm working with:
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
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
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
-
- Posts: 9451
- Joined: Fri Jul 09, 2004 5:18 pm
Re: XSL - testing if a document is valid
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/# ... -available
Regards,
Radu
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/# ... -available
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service