要求说明:我们的要求是查找目标为PubTbl且在输入xml文档中具有伪属性@rth的处理指令。这些处理指令特定于Arbortext Editor,它们在表格中显示整个XML文档。
<?PubTbl row rht="0.76in"?>
我们注意到,在我们的xml文档中的处理指令中,我们的ISO Schematron架构(如下所述)不会被触发。
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" id="vert-space-tables_schema"
queryBinding="xslt2" schemaVersion="iso">
<title>Forcing vertical space in content within tables</title>
<pattern id="vert-space-tables_pattern">
<title>Forcing vertical space in content within tables</title>
<rule id="vert-space-tables_processing-inst_rule" context="processing-instruction('PubTbl')"
abstract="false">
<report test="contains(.,'rht=')">
The table have got processing instructions you are looking altered to modify
pagination. </report>
</rule>
</pattern>
</schema>
我正在使用附带的“ant-schematron-2010-04-14.jar”zip文件中的ISO schematron样式表,使用ant task
<taskdef name="schematron" classname="com.schematron.ant.SchematronTask"
classpath="${lib}/ant-schematron-2010-04-14.jar; ${lib}/resolver.jar"/>
<schematron schema="${schema}/vert-space-tables/vert-space-tables.sch" failonerror="false"
queryLanguageBinding="xslt2" format="svrl" OutputDir="${dist}/vert-space-tables"
outputFilename="fail.xml" debugMode="true" failOnError="false" diagnose="true" classpathref="saxon-loc">
<fileset dir="${xml}/vert-space-tables" includes="Forcing_vertical_space_in_content_within_tables-fail.xml"/>
</schematron>
“debug.xslt” - 还附加了从ISO schematron生成的XSL样式表,并根据xml文档进行了验证。
在debug.xslt中(在文件的底部),我注意到apply-templates只处理元素节点,它永远不会处理 - 指令被处理,这是为什么?
<xsl:template match="@*|node()" priority="-2" mode="M1">
<xsl:apply-templates select="*****" mode="M1"/>
</xsl:template>
debug.xslt内容下面:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:schold="http://www.ascc.net/xml/schematron"
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
version="2.0"><!--Implementers: please note that overriding process-prolog or process-root is
the preferred method for meta-stylesheets to use where possible. -->
<xsl:param name="archiveDirParameter"/>
<xsl:param name="archiveNameParameter"/>
<xsl:param name="fileNameParameter"/>
<xsl:param name="fileDirParameter"/>
<xsl:variable name="document-uri">
<xsl:value-of select="document-uri(/)"/>
</xsl:variable>
<!--PHASES-->
<!--PROLOG-->
<xsl:output xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
method="xml"
omit-xml-declaration="no"
standalone="yes"
indent="yes"/>
<!--XSD TYPES FOR XSLT2-->
<!--KEYS AND FUNCTIONS-->
<!--DEFAULT RULES-->
<!--MODE: SCHEMATRON-SELECT-FULL-PATH-->
<!--This mode can be used to generate an ugly though full XPath for locators-->
<xsl:template match="*" mode="schematron-select-full-path">
<xsl:apply-templates select="." mode="schematron-get-full-path"/>
</xsl:template>
<!--MODE: SCHEMATRON-FULL-PATH-->
<!--This mode can be used to generate an ugly though full XPath for locators-->
<xsl:template match="*" mode="schematron-get-full-path">
<xsl:apply-templates select="parent::*" mode="schematron-get-full-path"/>
<xsl:text>/</xsl:text>
<xsl:choose>
<xsl:when test="namespace-uri()=''">
<xsl:value-of select="name()"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>*:</xsl:text>
<xsl:value-of select="local-name()"/>
<xsl:text>[namespace-uri()='</xsl:text>
<xsl:value-of select="namespace-uri()"/>
<xsl:text>']</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="preceding"
select="count(preceding-sibling::*[local-name()=local-name(current()) and namespace-uri() = namespace-uri(current())])"/>
<xsl:text>[</xsl:text>
<xsl:value-of select="1+ $preceding"/>
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="@*" mode="schematron-get-full-path">
<xsl:apply-templates select="parent::*" mode="schematron-get-full-path"/>
<xsl:text>/</xsl:text>
<xsl:choose>
<xsl:when test="namespace-uri()=''">@<xsl:value-of select="name()"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>@*[local-name()='</xsl:text>
<xsl:value-of select="local-name()"/>
<xsl:text>' and namespace-uri()='</xsl:text>
<xsl:value-of select="namespace-uri()"/>
<xsl:text>']</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--MODE: SCHEMATRON-FULL-PATH-2-->
<!--This mode can be used to generate prefixed XPath for humans-->
<xsl:template match="node() | @*" mode="schematron-get-full-path-2">
<xsl:for-each select="ancestor-or-self::*">
<xsl:text>/</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:if test="preceding-sibling::*[name(.)=name(current())]">
<xsl:text>[</xsl:text>
<xsl:value-of select="count(preceding-sibling::*[name(.)=name(current())])+1"/>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:if test="not(self::*)">
<xsl:text/>/@<xsl:value-of select="name(.)"/>
</xsl:if>
</xsl:template>
<!--MODE: SCHEMATRON-FULL-PATH-3-->
<!--This mode can be used to generate prefixed XPath for humans
(Top-level element has index)-->
<xsl:template match="node() | @*" mode="schematron-get-full-path-3">
<xsl:for-each select="ancestor-or-self::*">
<xsl:text>/</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:if test="parent::*">
<xsl:text>[</xsl:text>
<xsl:value-of select="count(preceding-sibling::*[name(.)=name(current())])+1"/>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:if test="not(self::*)">
<xsl:text/>/@<xsl:value-of select="name(.)"/>
</xsl:if>
</xsl:template>
<!--MODE: GENERATE-ID-FROM-PATH -->
<xsl:template match="/" mode="generate-id-from-path"/>
<xsl:template match="text()" mode="generate-id-from-path">
<xsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
<xsl:value-of select="concat('.text-', 1+count(preceding-sibling::text()), '-')"/>
</xsl:template>
<xsl:template match="comment()" mode="generate-id-from-path">
<xsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
<xsl:value-of select="concat('.comment-', 1+count(preceding-sibling::comment()), '-')"/>
</xsl:template>
<xsl:template match="processing-instruction()" mode="generate-id-from-path">
<xsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
<xsl:value-of select="concat('.processing-instruction-', 1+count(preceding-sibling::processing-instruction()), '-')"/>
</xsl:template>
<xsl:template match="@*" mode="generate-id-from-path">
<xsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
<xsl:value-of select="concat('.@', name())"/>
</xsl:template>
<xsl:template match="*" mode="generate-id-from-path" priority="-0.5">
<xsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="concat('.',name(),'-',1+count(preceding-sibling::*[name()=name(current())]),'-')"/>
</xsl:template>
<!--MODE: GENERATE-ID-2 -->
<xsl:template match="/" mode="generate-id-2">U</xsl:template>
<xsl:template match="*" mode="generate-id-2" priority="2">
<xsl:text>U</xsl:text>
<xsl:number level="multiple" count="*"/>
</xsl:template>
<xsl:template match="node()" mode="generate-id-2">
<xsl:text>U.</xsl:text>
<xsl:number level="multiple" count="*"/>
<xsl:text>n</xsl:text>
<xsl:number count="node()"/>
</xsl:template>
<xsl:template match="@*" mode="generate-id-2">
<xsl:text>U.</xsl:text>
<xsl:number level="multiple" count="*"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="string-length(local-name(.))"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="translate(name(),':','.')"/>
</xsl:template>
<!--Strip characters--><xsl:template match="text()" priority="-1"/>
<!--SCHEMA SETUP-->
<xsl:template match="/">
<svrl:schematron-output xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
title="Forcing vertical space in content within tables"
schemaVersion="iso">
<xsl:comment>
<xsl:value-of select="$archiveDirParameter"/>
<xsl:value-of select="$archiveNameParameter"/>
<xsl:value-of select="$fileNameParameter"/>
<xsl:value-of select="$fileDirParameter"/>
</xsl:comment>
<svrl:active-pattern>
<xsl:attribute name="document">
<xsl:value-of select="document-uri(/)"/>
</xsl:attribute>
<xsl:attribute name="id">vert-space-tables_pattern</xsl:attribute>
<xsl:attribute name="name">Forcing vertical space in content within tables</xsl:attribute>
<xsl:apply-templates/>
</svrl:active-pattern>
<xsl:apply-templates select="/" mode="M1"/>
</svrl:schematron-output>
</xsl:template>
<!--SCHEMATRON PATTERNS-->
<svrl:text xmlns:svrl="http://purl.oclc.org/dsdl/svrl">Forcing vertical space in content within tables</svrl:text>
<!--PATTERN vert-space-tables_patternForcing vertical space in content within tables-->
<svrl:text xmlns:svrl="http://purl.oclc.org/dsdl/svrl">Forcing vertical space in content within tables</svrl:text>
<!--RULE vert-space-tables_processing-inst_rule-->
<xsl:template match="processing-instruction('PubTbl')" priority="1000" mode="M1">
<svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
context="processing-instruction('PubTbl')"
id="vert-space-tables_processing-inst_rule"/>
<!--REPORT -->
<xsl:if test="contains(., 'breakpenalty="-10000"') or contains(., 'breakpenalty="2000"') or contains(.,'rht=')">
<svrl:successful-report xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
test="contains(., 'breakpenalty="-10000"') or contains(., 'breakpenalty="2000"') or contains(.,'rht=')">
<xsl:attribute name="location">
<xsl:apply-templates select="." mode="schematron-select-full-path"/>
</xsl:attribute>
<svrl:text>
The table have got processing instructions you are looking altered to modify
pagination. </svrl:text>
</svrl:successful-report>
</xsl:if>
<xsl:apply-templates select="*" mode="M1"/>
</xsl:template>
<xsl:template match="text()" priority="-1" mode="M1"/>
<xsl:template match="@*|node()" priority="-2" mode="M1">
<xsl:apply-templates select="*" mode="M1"/>
</xsl:template>
</xsl:stylesheet>
谢谢和问候, 苏雷什。
答案 0 :(得分:1)
运行此schematron文件(从上面复制)时,我无法复制此问题:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" id="vert-space-tables_schema"
queryBinding="xslt2" schemaVersion="iso">
<title>Forcing vertical space in content within tables</title>
<pattern id="vert-space-tables_pattern">
<title>Forcing vertical space in content within tables</title>
<rule id="vert-space-tables_processing-inst_rule" context="processing-instruction('PubTbl')"
abstract="false">
<report test="contains(.,'rht=')">
The table have got processing instructions you are looking altered to modify
pagination. </report>
</rule>
</pattern>
</schema>
针对这个xml:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<?PubTbl row rht="0.76in"?>
</root>
使用Oxygen 14的schematron实现,我收到以下消息:
Warning: unrecognized element svrl:schematron-output
当我下载http://schematron.googlecode.com/files/ant-schematron-2010-04-14.jar并使用iso_svrl_for_xslt2.xsl来编译schematron时,然后针对示例xml运行它,我得到以下svrl:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svrl:schematron-output xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/"
xmlns:schold="http://www.ascc.net/xml/schematron"
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
title="Forcing vertical space in content within tables"
schemaVersion="iso"><!--
--><svrl:active-pattern document="file:/Users/nunes/Desktop/tmp/test.xml"
id="vert-space-tables_pattern"
name="Forcing vertical space in content within tables"/>
</svrl:schematron-output>
当我从同一个jar中运行iso_schematron_message.xsl时,我也收到了消息:
Warning: unrecognized element svrl:schematron-output
当我使用我使用指定jar中的样式表生成的xsl来区分你的debug.xslt时(在运行Oxygen之后整理它们以规范化空格)我看到了这些差异:
--- debug.xslt 2012-11-10 00:19:39.000000000 -0800
+++ iso.xsl 2012-11-10 00:19:14.000000000 -0800
@@ -310 +310 @@
- test="contains(., 'breakpenalty="-10000"') or contains(., 'breakpenalty="2000"') or contains(.,'rht=')">
+ test="contains(.,'rht=')">
@@ -312 +312 @@
- test="contains(., 'breakpenalty="-10000"') or contains(., 'breakpenalty="2000"') or contains(.,'rht=')"
+ test="contains(.,'rht=')"
您确定要使用上面粘贴的schematron并使用正确的样式表进行解析吗?