[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [xml] Will xmllint use schematron?



>   I read http://www.schematron.com/iso/ quickly. I didn't understand it.

It's not a very good site, IMHO. However, schematron itself is quite a
neat idea.

> It seems it would require XSLT and EXSLT so it would not be implementable
> at the libxml2 level since XSLT and EXSLT are provided in libraries separate
> from libxml2.

I believe that only XPath is required, so it would be possible, but I
agree with Daniel that it would be better implemented as a seperate tool
on top of libxml/libxslt.

The implementation is fairly trivial, and there are existing
implementations in XSLT:

http://xml.ascc.net/schematron/1.5/

I've used some of the sample metastylesheets with xsltproc, and have had
no problems. If you really want a programatic interface, here's a simple
start point...

/* Simple Schematron commandline util
   Based on skeleton1-5.xsl, from http://www.ascc.net/xml/schematron/1.5/

   S. Little
   20031103
*/

#include <iostream.h>
#include "libxslt/transform.h"
#include "libxslt/xsltutils.h"

const char * skeleton_xslfile="/path/to/skeleton1-5.xsl";

int main(int argc, char** argv)
{
  if(argc != 3){
    cout << "Usage:" << endl;
    cout << "\t" << argv[0] << " <schematron-schema-file> <xml-file>" <<
endl;
    return 1;
  }

  // generate schematron XSLT document
  xsltStylesheetPtr skeletonXsl = xsltParseStylesheetFile((const xmlChar
*)skeleton_xslfile);
  xmlDocPtr schematronDoc = xmlParseFile(argv[1]);
  xmlDocPtr schematronXml = xsltApplyStylesheet(skeletonXsl,
schematronDoc, NULL);

  // apply schematron XSLT document to input XML, to produce output
  xsltStylesheetPtr schematronXsl = xsltParseStylesheetDoc(schematronXml);
  xmlDocPtr input = xmlParseFile(argv[2]);
  xmlDocPtr output = xsltApplyStylesheet(schematronXsl,input, NULL);

  // Any analysis of the output can be done here.
  // For now, just dump to stdout
  xsltSaveResultToFile(stdout,output,schematronXsl);
}

You could make a metastylesheet makes it trivial to analyse the output for
problems.

A perl implementation on a similar principle exists:

http://www.xml.com/pub/a/2002/01/23/perl-schematron.html?page=2

Alternatively, you can parse the schematron schemafile yourself,
implement each tag, check the XPaths etc, and thus make a libxml only
version. Arguably that's a waste of time though, when there's a Free XSLT
implementation.

Hope that helps.

Steve



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]