Using XSLT to validate source XML's DTD
I fear this might be a FAQ but I can't figure out how to google for
Recently we had a big bug where the source that an XSL file acted on
changed out from under it. Result, the XSL matched nothing and
important content did not make it to the final destination.
I was under the impression that an XSL could be told "You will be
acting on an XML that is valid according to the following DTD." Thus,
if the XML that it was applied against was NOT what was expected, it
would crash rather than failing silently to match anything.
I do NOT want the DTD for the XSL file. Nor do I want to
independently validate the XML before sending it (because that
wouldn't solve my problem if the XSL does not know that the source has
changed). I need the XSL to be able to detect that the incoming XML
is no longer what it thinks it is.
Am I right?
Re: Using XSLT to validate source XML's DTD
In article <email@example.com >,
Duane Morin <firstname.lastname@example.org> wrote:
% I was under the impression that an XSL could be told "You will be
% acting on an XML that is valid according to the following DTD."
Some XSL processors will validate documents which include a DOCTYPE,
but it depends on the processor. Note that DTD validation is always
against a DTD specified in the XML document, so it might not be
helpful (for the reasons you note in the part I'm about to elide).
% changed). I need the XSL to be able to detect that the incoming XML
% is no longer what it thinks it is.
If the XSL is supposed to handle every element, you could create a
catch-all template and have it terminate
<xsl:message terminate='yes'>Oops. Didn't expect
this will be a problem if there are elements you currently want to
Failing that, you could write a schema using xml schema or relax ng and
apply that as part of the xslt processing. You'd have to keep it in
synch with the style sheet, of course.
XSLT 2.0 can use schemas, but I believe the objective is to allow XPath
queries to involve data types, rather than to provide transform-time
Patrick TJ McPhee
East York Canada
|All times are GMT. The time now is 04:48 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.