xml::schematron::libxslt(3)

NAME

XML::Schematron::LibXSLT - Perl extension for validating
XML with XPath/XSLT expressions.

SYNOPSIS

use XML::Schematron::LibXSLT;
my $pseudotron = XML::Schematron::LibXSLT->new(schema =>
'my_schema.xml');
my $messages = $pseudotron->verify('my_doc.xml');
if ($messages) {
    # we got warnings or errors during validation...
    ...
}
OR, in an array context:
my $pseudotron = XML::Schematron::LibXSLT->new(schema =>
'my_schema.xml');
my @messages = $pseudotron->verify('my_doc.xml');
OR, just get the generated xsl:
my $pseudotron = XML::Schematron::LibXSLT->new(schema =>
'my_schema.xml');
my  $xsl = $pseudotron->dump_xsl; # returns the internal
XSLT stylesheet.

DESCRIPTION

XML::Schematron::LibXSLT serves as a simple validator for
XML based on Rick JELLIFFE's Schematron XSLT script. A
Schematron schema defines a set of rules in the XPath lan
guage that are used to examine the contents of an XML doc
ument tree.

A simplified example:
<schema>
<pattern>
<rule context="page">
<assert test="count(*)=count(title|body)">The page el
ement may only contain title or body elements.</assert>
<assert test="@name">A page element must contain a
name attribute.</assert>
<report test="string-length(@name) &lt; 5">A page ele
ment name attribute must be at least 5 characters long.</report>
</rule>
</pattern>
</schema>
Note that an 'assert' rule will return if the result of
the test expression is not true, while a 'report' rule
will return only if the test expression evalutes to true.

METHODS

new()
The 'new' constructor accepts the following "named"
arguments:
· schema
The filename of the schema to use for generating
tests.
· tests
The tests argument is an alternative to the use of a schema as a means for defining the test stack.
It should be a reference to a list of lists where
the format of the sub-lists must conform to the
following order:

[$xpath_exp, $context, $message, $test_type,
$pattern]
schema()
When called with a single scalar as its argument, this
method sets/updates the schema file to be used for
generatng tests. Otherwise, it simply returns the name
of the schema file (if any).
tests()
When called with a reference to a list of lists as its
argument (see the format in the description of the
'tests' argument to the new() method for details),
this method sets the current test stack. Otherwise, it
returns an arrayref to the current test stack (if
any).
add_test(%args);
The add_test() method allows you push additional tests on to the stack before validation using the typical
"hash of named parameters" style.
Arguments for this method:
· expr (required)
The XPath expression to evaluate.
· context (required)
An element name or XPath location to use as the
context of the test expression.
· type (required)
The type argument must be set to either 'assert'
or 'report'. Assert tests will return the associ
ated message only if the the corresponding test
expression is not true, while 'report' tests will
return only if their associated test expression
are true.
· message (required)
The text message to display when the test condi
tion is met.
· pattern (optional)
Optional descriptive text for the returned message
that allows a logical grouping of tests.
Example:

$obj->add_test(expr => 'count(@*) > 0',
context => '/pattern',
message => 'Pattern should have
at least one attribute',
type => 'assert',
pattern => 'Basic tests');
Note that add_test() pushes a new test on to the existing test list, while tests() redefines the
entire list.
verify('my_xml_file.xml' or $some_xml_string)
The verify() method takes the path to the XML document that you wish to validate, or a scalar containing the
entire document as a string, as its sole argument. It
returns the messages that are returned during valida
tion. When called in an array context, this method
returns an array of the messages generated during
validation. When called in a scalar context, this
method returns a concatenated string of all output.
dump_xsl;
The dump_xsl method will return the internal XSLT
script created from your schema.

CONFORMANCE

Internally, XML::Schematron::LibXSLT uses the Gnome Pro
ject's XSLT proccessor via XML::LibXSLT and, while this
proccessor is not 100% compliant with the XSLT spec at the
time of this writing, it is the best XSLT libraray avail
able to the Perl World at the moment. It is therefore pos
sible that you might use a completely valid XSLT expres
sion within one of your schema's tests that will cause
this module to die unexpectedly.

For those platforms on which libxslt is not available,
please see the documentation for XML::Scmeatron::Sablotron
and XML::Schematron::XPath (also in this distribution) for
alternatives.

AUTHOR

Kip Hampton, khampton@totalcinema.com

COPYRIGHT

Copyright (c) 2000 Kip Hampton. All rights reserved. This
program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

SEE ALSO

For information about Schematron, sample schemas, and
tutorials to help you write your own schmemas, please
visit the Schematron homepage at:
http://www.ascc.net/xml/resource/schematron/

For information about how to install libxslt and the nec
essary XML::LibXSLT Perl module, please see http://xml
soft.org/XSLT/ and CPAN, repectively.

For detailed information about the XPath syntax, please
see the W3C XPath Specification at:
http://www.w3.org/TR/xpath.html
Copyright © 2010-2025 Platon Technologies, s.r.o.           Index | Man stránky | tLDP | Dokumenty | Utilitky | O projekte
Design by styleshout