質問

Requirement Description: our requirement is to looks for the processing instruction whose target is PubTbl and which have got pseudo-attribute @rth in input xml document. These processing instructions are specific to Arbortext Editor and they present all over the XML document with in tables.

<?PubTbl row rht="0.76in"?>

We have noticed that at processing-instructions in our xml document our ISO Schematron schema (mentioned below) is not getting fired.

  • Does n't ISO Schematron validate processing instruction?
  • If ISO Schematron validates processing instructions, is there any setting/param change i need to take care?

ISO Schematron schema

<?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>

I am using the ISO schematron stylesheets present in the "ant-schematron-2010-04-14.jar" zip file attached, using 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" - also attached is the XSL stylesheets generated from ISO schematron and validated against the xml document.

With in debug.xslt (at bottom of the file), I have noticed that apply-templates only processes element nodes that way it never gets to processing-instrucitons gets handled, is this why?

<xsl:template match="@*|node()" priority="-2" mode="M1">
              <xsl:apply-templates select="*****" mode="M1"/>
           </xsl:template>

debug.xslt content Below:

<?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=&#34;-10000&#34;') or contains(., 'breakpenalty=&#34;2000&#34;') or contains(.,'rht=')">
         <svrl:successful-report xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
                                 test="contains(., 'breakpenalty=&#34;-10000&#34;') or contains(., 'breakpenalty=&#34;2000&#34;') 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>

Thanks and regards, Suresh.

役に立ちましたか?

解決

I'm unable to duplicate this problem when I run this schematron file (copied from above):

<?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>

against this xml:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <?PubTbl row rht="0.76in"?>  
</root>

using Oxygen 14's schematron implementation I get the following message:

Warning: unrecognized element svrl:schematron-output

When I download http://schematron.googlecode.com/files/ant-schematron-2010-04-14.jar and use iso_svrl_for_xslt2.xsl out of it to compile the schematron, then run that against the sample xml I get the following 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>

which when I then run against iso_schematron_message.xsl from the same jar, I also get the message:

Warning: unrecognized element svrl:schematron-output

When I diff your debug.xslt with the xsl that I generated using the stylesheet from the specified jar (after running Oxygen's tidy on them both to normalize whitespace) I see these differences:

--- 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=&#34;-10000&#34;') or contains(., 'breakpenalty=&#34;2000&#34;') or contains(.,'rht=')">
+      test="contains(.,'rht=')">
@@ -312 +312 @@
-        test="contains(., 'breakpenalty=&#34;-10000&#34;') or contains(., 'breakpenalty=&#34;2000&#34;') or contains(.,'rht=')"
+        test="contains(.,'rht=')"

Are you sure you're using the schematron that you've pasted above and parsing it with the correct stylesheet?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top