Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Fix attribute parameter #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Robbert
Copy link

@Robbert Robbert commented Mar 7, 2017

Currently the attribute XSLT parameter is ineffective because of the erroneous parent::node() check. Removing the needless check should resolve issue #29, and allow attributes as rule context again.

@andreastai
Copy link

Thanks @Robbert for providing the patch and @gkholman for the bug description.

@rjelliffe @tgraham-antenna Could you do the merge after review and publish an update stylesheet collection on schematron.org? We needed some time to find out what was wrong with our schematron schemas and I assume others will also invest some time. This is a quite substantial issue and because the rest of the implementation works so well you actually do not expect that this is a bug.

@andreastai
Copy link

@Robbert This PR seems not to fully fix the problem (or it has at least another unwanted effect).

With this fix you could now use also attribute nodes as context for a rule. But when an assertion fails, the location attribute in the SVRL report has not the expected XPATH.

Example

Source File

<foo>
	<bar baz="hello world"/>
</foo>

Schematron Schema

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
    <sch:pattern>
        <sch:rule context="@baz">
            <sch:assert test="false()">There is no attribute @baz on any element.</sch:assert>
        </sch:rule>
    </sch:pattern>
</sch:schema>

SVRL Message

   <svrl:failed-assert test="false()" location="hello world">
      <svrl:text>There is no attribute @baz on any element.</svrl:text>
   </svrl:failed-assert>

@location does not contain the XPATH to the "error attribute" but the value of the attribute.

Problem

This following part in the schematron skeleton for saxon seems the problem.

<xsl:template name="generate-default-rules">
	...
	<axsl:template match="*" mode="schematron-select-full-path">
		<xsl:choose>
			<xsl:when test=" $full-path-notation = '1' ">
				<!-- Use for computers, but rather unreadable for humans -->
				<axsl:apply-templates select="." mode="schematron-get-full-path"/>
			</xsl:when>
   ...
			<xsl:otherwise>
			...
			</xsl:otherwise>
		</xsl:choose>
	</axsl:template>
</xsl:template>

The generated template for mode chematron-select-full-path matches only elements but no attributes.

Solution?

If the generated template also matches attrbiutes this seem to fix the problem

<axsl:template match="@*|*" mode="schematron-select-full-path">..</axsl:template>

For the example above I now get

   <svrl:failed-assert test="false()" location="/foo[1]/bar[1]/@baz">
      <svrl:text>There is no attribute @baz on any element.</svrl:text>
   </svrl:failed-assert>

@spoeschel
Copy link

It should be noted that there is unfortunately another undesired side effect when Saxon is used:

When a rule context targets e.g. the document node or an attribute node, such a node cannot have any attribute children and so Saxon will emit a warning like the following:

(...)
Warning at char 2 in xsl:apply-templates/@select on line 523 column 55 of bla.xslt:
  SXWN9000: The attribute axis starting at an attribute node node will never select anything
(...)
Warning at char 2 in xsl:apply-templates/@select on line 828 column 55 of bla.xslt:
  SXWN9000: The attribute axis starting at a document node node will never select anything
(...)

tjeb pushed a commit to peppolautoriteit-nl/validation that referenced this pull request Oct 17, 2018
tjeb referenced this pull request in peppolautoriteit-nl/validation Oct 17, 2018
@tgraham-antenna tgraham-antenna added fix Solution for a bug or enhancement review wanted Needs review before acceptance labels Feb 28, 2020
AirQuick referenced this pull request in 18F/fedramp-automation Jul 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fix Solution for a bug or enhancement review wanted Needs review before acceptance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants