Using XSLT to validate source XML's DTD

Discussion in 'XML' started by Duane Morin, Dec 11, 2003.

  1. Duane Morin

    Duane Morin Guest

    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
     
    Duane Morin, Dec 11, 2003
    #1
    1. Advertising

  2. In article <>,
    Duane Morin <> 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
     
    Patrick TJ McPhee, Dec 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    683
    Stylus Studio
    Aug 3, 2004
  2. Joseph Tilian
    Replies:
    0
    Views:
    354
    Joseph Tilian
    Dec 21, 2004
  3. Replies:
    2
    Views:
    426
  4. Replies:
    0
    Views:
    1,269
  5. test
    Replies:
    2
    Views:
    2,042
    Oliver Wong
    Jul 28, 2006
Loading...

Share This Page