I have a problem with validating XML with schematron.
In my code I load the XML and XSL as DOMDocument objects and I try to transform:
$domSche = new DOMDocument();
$domSche->loadXML($message);
$domXSLSche = new DOMDocument();
$domXSLSche->load("CI-SIS_StructurationCommuneCDAr2.xsl");
$xsltsche = new XSLTProcessor();
$xsltsche->importStylesheet($domXSLSche);
$XSLValid = $xsltsche->transformToXml($domSche);
But the function returns this error:
XSLTProcessor::transformToXml(): No stylesheet associated to this object
I don't understand, technically, the importStylesheet associates my XSL to the XML, no?
If someone wants to look at more sources, files are at :
The Schematron version you make use of does not require XSL 2.0 however the file you have makes use of XSL 2.0 features.
XSLTProcessor
in PHP supports XSL 1.0 only. Some of the features used in that file are therefore not available and make the import fail.
As the stylesheet could not be imported, the transformation can not run.
The error message
Warning: XSLTProcessor::transformToXml(): No stylesheet associated to this object
means that the stylesheet is missing. Not on disk or in memory, but for the transformation.
That is because it has errors and finally could not compile.
In your case the XSL file you have is of version 2.0 but PHP only supports 1.0 features. Also it makes use of variables that are not set (defined). When I load your example data I get the following errors:
Warning: XSLTProcessor::importStylesheet(): compilation error: file CI-SIS_StructurationCommuneCDAr2.xsl line 13 element stylesheet
Which is:
version="2.0">
and explained by the next warning:
Warning: XSLTProcessor::importStylesheet(): xsl:version: only 1.0 features are supported
Next is an undefined variable:
Warning: XSLTProcessor::importStylesheet(): Undefined variable
Warning: XSLTProcessor::importStylesheet(): compilation error: file CI-SIS_StructurationCommuneCDAr2.xsl line 4974 element template
which is
<!--RULE -->
<xsl:template match="*[cda:templateId/@root = $templateObservationMedia]" priority="1000"
mode="M62">
which is the $templateObservationMedia
variable and leads to
Warning: XSLTProcessor::importStylesheet(): Failed to compile predicate
To get this working you would need at least fix these problems. As using the variable inside the match pattern is not XSLT 1.0 you need to work around that at least. See Multiple PHP Warnings in XSLTProcessor::importStylesheet() for an extended discussion of the variable/match issue.