Examples of using the library PreviousNext

This chapter deals with examples of how to invoke XSLT transformations from within your Eiffel programs. It does not cover writing XSLT programs. For that you should look elsewhere (a good starting point is the XSLT FAQ).

A Schematron validator

In $GOBO/library/xslt/example/schematron , there is a complete example of using the library. This is a command-line validator using the Schematron language. See the Readme.md file for instructions on compiling and using the program.

The creation procedure make starts by creating a configuration, and then it sets the recovery policy to recover from recoverable errors without writing any error messages. Because the program uses Eiffel STRINGs for the result of a transformation (and also for the source of a stylesheet), it next goes on to create a XM_STRING_URI_RESOLVER, so that the XML parser can locate the STRINGs involved.

After processing the command line arguments, it then performs the first stage - a transformation of a Schematron rules file (a schema) into a stylesheet (which will be used to perform the actual validation). This is performed by transform_schematron_rules. This is fairly straightforward. The only thing of particular note is that the resulting STRING has to be plugged into the resolver, as the XML parser needs to find it in the next stage of the program

At this point, we have the result of transform_schematron_rules in a STRING. Interestingly, the contents of this STRING is another XSLT stylesheet. We now go on to use this stylesheet to perform a transformation against the file which is to be validated. This is done in create_report. The interesting code in this case arises if the user has requested output to a file, rather than standard output. Notice that although the program takes filenames (for the convenience of the user), the transform feature of XM_XSLT_TRANSFORMER takes arguments that require URIs for their creation procedures. This is a requirement of the XSLT specification.

The Schematron validator program writes a report to standard output or to a file, if validation fails. If validation is successful, then no output is produced. This situation could be detected by writing the output to a STRING instead, and checking if it's count were zero (successful validation), or not (an error report has been produced). So if you wanted to use the XSLT library to perform Schematron validation from within your own programs, then this is how you would do it.

Gexslt

The Gobo Eiffel XSLT command line processor comes close to being the ultimate example of how to use the XSLT library, in as much as it allows most options to be used. You can see the source in $GOBO/src/gexslt/gexslt.e .

Gestalt

Other examples are in the Gestalt distribution (see Gestalt).


Copyright 2005-2017, Colin Adams and others
mailto:colin@colina.demon.co.uk
http://www.gobosoft.com
Last Updated: 8 January 2017
HomeTocPreviousNext