我正在尝试跟随这篇关于Schematron和Perl的文章。
http://www.xml.com/pub/a/2002/01/23/perl-schematron.html?page=2
我的目标是使用Schematron和RelaxNG来验证Docbook5文档。
然而,我似乎不能让这个基本的例子工作。下面是我的Perl脚本,从O‘’Reilly文章中复制:
#!/usr/bin/perl -w
use strict;
use XML::Schematron::LibXSLT;
my $schema_file = $ARGV[0];
my $xml_file = $ARGV[1];
die "Usage: perl schematron.pl schemafile XMLfile.\n"
unless defined $schema_file and defined $xml_file;
my $tron = XML::Schematron::LibXSLT->new();
$tron->schema($schema_file);
my $ret = $tron->verify($xml_file);
print $ret . "\n";我这样调用脚本:
perl schematron.pl到docbook.sch的路径到xml文件的路径
我得到了与名称空间“db”有关的错误:
xsltCompileStepPattern : no namespace bound to prefix db
compilation error: file unknown-101d82900 element template
xsltCompilePattern : failed to compile 'db:sidebar'
error
...我的docbook.sch文件开始如下所示。它是Docbook5发行版附带的docbook.sch模式文件:
<?xml version="1.0" encoding="utf-8"?>
<s:schema xmlns:s="http://www.ascc.net/xml/schematron" xmlns:db="http://docbook.org/ns/docbook">
<s:ns prefix="db" uri="http://docbook.org/ns/docbook"/>
<s:pattern name="Element exclusion">
<s:rule context="db:sidebar">可能是Perl模块使用了不理解名称空间的Schematron版本吗?或者可能是docbook.sch是不正确的?这会很奇怪,因为它是随Docbook发行版一起提供的。
我可能遗漏了一些基本的东西,因为我是Schematron的新手。
发布于 2013-08-26 02:00:06
这看起来像是XML::Schematron中的一个错误。不考虑docbook.sch中的以下行:
<s:ns prefix="db" uri="http://docbook.org/ns/docbook"/> 验证通过将模式转换为XSLT样式表来完成。我可以通过在XSLTProcessor.pm模块中添加DocBook名称空间声明来消除这个错误:
$self->append_template(
qq|<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet $ns version="1.0"
xmlns:db="http://docbook.org/ns/docbook">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="/" mode="$mode"/>|
);上面的只是一个小技巧。当然,适当的修复(我还没有尝试过)应该适用于在Schematron模式中声明的任何名称空间。
https://stackoverflow.com/questions/17799853
复制相似问题