By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,492 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,492 IT Pros & Developers. It's quick & easy.

Using XSLT to validate source XML's DTD

P: n/a
I fear this might be a FAQ but I can't figure out how to google for
it.

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?

Duane
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <55**************************@posting.google.com >,
Duane Morin <dm****@morinfamily.com> 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:template match="*">
<xsl:message terminate='yes'>Oops. Didn't expect
<xsl:value-of select='name'/>.
</xsl:message>
</xsl:template>

this will be a problem if there are elements you currently want to
ignore.

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

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.