PSRule - Failed to compile XPath expression in <rule>: '//*[. is nf:get-document-element(.)]'
wahowaho opened this issue · 14 comments
hello,i have a question, content is: why Cannot find a 1-argument function named Q{http://reference.niem.gov/niem/specification/naming-and-design-rules/4.0/#NDRFunctions}get-document-element(). External function calls have been disabled,
schamatron is :
<sch:pattern id="rule_7-4"><sch:title>Document element is xs:schema</sch:title>
<sch:rule context="*[. is nf:get-document-element(.)]">
<sch:assert test="self::xs:schema">Rule 7-4: The [document element] of the [XML document] MUST have the name xs:schema.</sch:assert>
</sch:rule>
</sch:pattern>
xml is :
<?xml version="1.0" encoding="UTF-8"?>
<xs:import schemaLocation="../../utility/structures/1.0/structures.xsd" namespace="http://release.ciem.org/ciem/structures/1.0/"/>
<xs:schema targetNamespace="http://release.ciem.org/ciem/sample/1.0/NegativeSample-4-1-1/" version="1.0"
xsi:schemaLocation="http://release.ciem.org/ciem/sample/1.0/ ../../sample/1.0/NegativeSample-4-1-1.xsd"
appinfo:defaultPrefix="NS-4-1-1" attributeFormDefault="qualified"
blockDefault="" elementFormDefault="qualified"
finalDefault="" xml:lang="/" xmlns:NS-4-1-1="http://release.ciem.org/ciem/sample/1.0/NegativeSample-4-1-1/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty"
xmlns:structures="http://release.ciem.org/ciem/structures/1.0/"
xmlns:appinfo="http://release.ciem.org/ciem/appinfo/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:annotation>
<xs:documentation xml:lang="EN">The negative sample for the rule_7-4 in chapter 4.</xs:documentation>
</xs:annotation>
</xs:schema>
thanks
Hi.
There is an error in the XML: "import" must be a child of "schema".
The topic of custom functions is tricky - you must supply them from the outside, or they must be part of the Schematron file itself.
- Please paste the full Schematron (if possible)
- What engine are you using? Must be "xslt" or "sch" to work?
- How do you invoke it? Plain Java code? Maven plugin? ANT taks?
hello ! schematron is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" queryBinding="xslt2">
<sch:title>NIEM example</sch:title>
<xsl:include href="ndr-functions.xsl"/>
<sch:ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>
<sch:ns prefix="xsl" uri="http://www.w3.org/1999/XSL/Transform"/>
<sch:ns prefix="nf" uri="http://reference.niem.gov/niem/specification/naming-and-design-rules/4.0/#NDRFunctions"/>
<sch:ns prefix="ct" uri="http://release.niem.gov/niem/conformanceTargets/3.0/"/>
<sch:ns prefix="xsi" uri="http://www.w3.org/2001/XMLSchema-instance"/>
<sch:ns prefix="appinfo" uri="http://release.niem.gov/niem/appinfo/4.0/"/>
<sch:ns prefix="structures" uri="http://release.niem.gov/niem/structures/4.0/"/>
<sch:pattern id="rule_7-4"><sch:title>Document element is xs:schema</sch:title>
<sch:rule context="*[. is nf:get-document-element(.)]">
<sch:assert test="self::xs:schema">Rule 7-4: The [document element] of the [XML document] MUST have the name xs:schema.</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
and i change my xml to :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://release.niem.org/niem/sample/1.0/NegativeSample-4-1-1/" version="1.0"
blockDefault="" elementFormDefault="qualified"
finalDefault=""
xmlns:NS-4-1-1="http://release.niem.org/niem/sample/1.0/NegativeSample-4-1-1/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty">
<xs:annotation>
<xs:documentation xml:lang="EN">The negative sample for the rule 4-1 in chapter 4.</xs:documentation>
</xs:annotation>
</xs:schema>
thank you very much
invoke it by Plain Java code final PSReader aReader = new PSReader(aRes);
Ok thanks. Schematron looks okay.
Try this code as basis for validation:
final ISchematronResource aSV = SchematronResourceSCH.fromfromFile ("patth/to/your.sch");
final Document aDoc = aSV.applySchematronValidation (new FileSystemResource ("path/to/your.xml"));
System.out.println (com.helger.xml.serialize.write.XMLWriter.getNodeAsString (aDoc));
Please ensure that the included XSL resides in the same folder as the SCH file
hello!I'm sorry to bother you. i have try my best to do it,but it doesnt work. i cant find the reason. I wish to ask a favour of you. i push my project to github, I hope to get your help. ,I'm sorry to take up your time. think you very much ,thank you https://github.com/SnowMakerDemo/schematronTest.git
It is indeed tricky - never used Schematron with XSLT includes.... Will play around with it and let you know :)
OK thank you ,very thanks , i will change the content to xpath ,thank you :)
hello i have another question。:)
exists(@appinfo:externalAdapterTypeIndicator) can not find an atrribute by "appinfo:externalAdapterTypeIndicator" , @appinfo:externalAdapterTypeIndicator != appinfo:externalAdapterTypeIndicator = "123"
but after remove ":" , Everything is running well.
thank you。
schematron is :
<sch:pattern id="rule_10-10">sch:titletest</sch:title>
<sch:rule context="xs:complexType[exists(@appinfo:externalAdapterTypeIndicator)]">
<sch:assert test="@appinfo:externalAdapterTypeIndicator ='123'">Rule 10-10: test.</sch:assert>
</sch:rule>
</sch:pattern>
xml is :
<xs:complexType id="123" name="annotationNegativeType" appinfo:externalAdapterTypeIndicator = "123">
</xs:complexType>
I am out of office today. You need to declare the appinfo NS prefix explicitly. Attributes with namespaces are tricky in XPath...
thank you,I'm particularly grateful to you for having taken time out of your busy schedules to reply me. the holiday,i got merried,I didn't reply to you in time. that question is my mistake, sch import uri is different from xml import , i change it, now it‘s ok thank you
Ah okay - congratulations on your marriage 😄
So you made it work? Can you please post your code here, because I also tried "sch:import" but I failed.
Thank you.
thank you,:) schematron : <sch:ns prefix="appinfo" uri="http://release.niem.gov/niem/appinfo/4.0/"/>
xml: xmlns:appinfo="http://release.nime.org/ciem/appinfo/1.0/" ,they are different from each other, when schematron check xml, schematron can not find appinfo exactly. its my second question what i said. but i think that is not you want what the question of sch:import . i did not modify the java code。im sorry,i let you down。
I think I found the error and fixed it in 5.1.0. The problem was a missing URLResolver
for the created XSLT. I added a test for it and additionally improved the automatic URL resolver base URL determination. See https://github.com/phax/ph-schematron/blob/master/ph-schematron/src/test/resources/issues/github77/schematron.sch as the Schematron and https://github.com/phax/ph-schematron/blob/master/ph-schematron/src/test/java/com/helger/schematron/supplementary/Issue77Test.java for the respective test.
So
- use class
SchematronResourceSCH
and - allow foreign element via
aSCH.setAllowForeignElements (true);
(for security reasons I cannot make this the default).
I will create the 5.1.0 release soon
When I saw it, I was really happy, it solved my problem,thank you very much. 👍 👍