PHP code example of mmnewmedia / schematron-parser
1. Go to this page and download the library: Download mmnewmedia/schematron-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mmnewmedia / schematron-parser example snippets
use MMNewmedia\Schematron\Ast\XPathTokenizer;
use MMNewmedia\Schematron\Compiler\ExpressionCompiler;
use MMNewmedia\Schematron\Compiler\ExpressionNormalizer;
use MMNewmedia\Schematron\Compiler\FunctionLoader;
use MMNewmedia\Schematron\Compiler\XPathAstCompiler;
use MMNewmedia\Schematron\Parser\XPathAstParser;
$functionLoader = new FunctionLoader(
dirname(__DIR__) . '/vendor/mmnewmedia/schematron-parser/src/Schematron/Compiler/Functions',
'MMNewmedia\Schematron\Compiler\Functions',
);
$compiler = new ExpressionCompiler(
new XPathAstParser(new XPathTokenizer()),
new XPathAstCompiler($functionLoader->load()),
new ExpressionNormalizer(),
);
// XPath -> PHP expression evaluating against a context node ($context by default)
$php = $compiler->compile('substring-before(ram:ID, "-")', '$node');
// XPath -> PHP expression evaluating to a node-set (DOMNodeList)
$nodeSet = $compiler->compileNodeSet('.//ram:SpecifiedLineTradeTransaction', '$node');
use MMNewmedia\Schematron\SchematronCompilerService;
$service = new SchematronCompilerService($compiler, '/path/to/output/Rules/Cii');
$service->compile('/path/to/EN16931-CII-validation-preprocessed.sch', 'MyProject\Schematron\Rules\Cii');
public static function validate(DOMXPath $xpath, DOMNode $context): bool;
public static function message(): string;
public static function context(DOMXPath $xpath, DOMNode $context): iterable; // only when needed
use MMNewmedia\Schematron\Compiler\CodedbCodeList;
CodedbCodeList::setBaseDirectories(['/path/to/zugferd/_generated', '/path/to/zugferd/_preprocessed']);