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

Variables don't work in match #84

Open
itmachines opened this issue Aug 21, 2019 · 2 comments
Open

Variables don't work in match #84

itmachines opened this issue Aug 21, 2019 · 2 comments
Labels
question Question about Schematron or Schematron software

Comments

@itmachines
Copy link

itmachines commented Aug 21, 2019

I have been battling for a while now with a schematron rule that does not seem to evaluate my variable correctly leaving me with no correct match.

My example and rule should always fail the assertion, and write out the message (as a "Test") ... as I want one question for every one reference (and visa versa) ... but the count always comes up as ZERO!

Where my rule is as follows:

<pattern id="Question">
  <rule id="Count" context="question/@id">
    <let name="href" value="concat('#', ancestor::parent/@id, '/', .)" />
    <assert test="false()">
      question/@id=[<value-of select="." />] has [<value-of select="count(ancestor::parent//reference[@href eq $href)])" />] references with reference/@href=[<value-of select="$href" />])
  </assert>
</pattern>

My input XML is as follows:

<parent id="GUID-ABCDEFG">
	<question>
		<references>
			<reference href="#GUID-ABCDEFG/GUID-12345"/>
			<reference href="#GUID-ABCDEFG/GUID-67890"/>
		</references>
		<questions>
			<question id="GUID-12345">...</question>
			<question id="GUID-67890">...</question>
		</questions>
	</question>
</parent>

My output when rendering outputs the variables correctly:

Question::Count:[[question/@id=[GUID-12345] has [0] references with reference/@href=[#GUID-ABCDEFG/GUID-12345]

As you can see, zero, when it should find 1 match.

If I count "all" the references, then it DOES give me 2!

Now, if I hard-code the count as a string:
<value-of select="count(ancestor::parent//reference[@href eq '#GUID-ABCDEFG/GUID-12345'])" />
Then I do get the correct count/result!!

On another strange note: If I put a syntax error in my rule, the exception that is thrown shows me the "content" of the variable, not the value:

count(ancestor::question//data-about[@href eq concat('#', ancestor::question/@id, '/', .))])': syntax error, expecting ','

@PStellmann
Copy link

Hi Bradley,

after fixing the bugs in your schematron code it generated the expected output for me (Tested with oXygen xml 18.1):

<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2" xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
  <pattern id="Question">
    <rule id="Count" context="question/@id">
      <let name="href" value="concat('#', ancestor::parent/@id, '/', .)" />
      <assert test="false()">
        question/@id=[<value-of select="." />] has [<value-of select="count(ancestor::parent//reference[@href eq $href])" />] references with reference/@href=[<value-of select="$href" />])
      </assert>
    </rule>
  </pattern>
</schema>

Output:

question/@id=[GUID-12345] has [1] references with reference/@href=[#GUID-ABCDEFG/GUID-12345])
question/@id=[GUID-67890] has [1] references with reference/@href=[#GUID-ABCDEFG/GUID-67890])

About your exception: when the code is buggy there exists no value because the resulting script is not even being executed. Not sure what you expected here?

Regards,
Patrik

@itmachines
Copy link
Author

itmachines commented Aug 21, 2019

Hi Patrik,
Thank-you for your reply and confirmation that it does work for you! It must be the version that I am using that does not work. I am using a .Net version (so also perhaps not the right area to have posted my question as well - so my apology for that!)

[assembly: AssemblyTitle("SchemaTron")]
[assembly: AssemblyDescription("The native ISO Schematron validator over XPath 1.0 query language binding.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("The XRouter Team")]
[assembly: AssemblyProduct("SchemaTron")]
[assembly: AssemblyCopyright("Copyright © The XRouter Team 2011")]

If I update my schema as you have it with the correct bindings, I get an error within the API: {The value of the 'queryBinding' attribute ('xslt2') is not valid.}

  • So clearly not using the "better" version of Schematron perhaps.

Can you please, point me in a direction for a .Net API version of Schematron that is functional, so that I may replace the one that I have perhaps?

Again, thanks for your help and confirmation!!!

All the best,
Brad

@tgraham-antenna tgraham-antenna added the question Question about Schematron or Schematron software label Feb 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Question about Schematron or Schematron software
Projects
None yet
Development

No branches or pull requests

3 participants