I have some c# prototype code that compiles and then executes an XSLT.
var samplesDir = new Uri(AppDomain.CurrentDomain.BaseDirectory);
// Create a Processor instance.
Processor processor = new Processor(true);
var compiler = processor.NewXsltCompiler();
try
{
// Create a transformer for the stylesheet.
Xslt30Transformer transformer = compiler.Compile(new Uri(samplesDir, "po.xsl")).Load30();
// Create a serializer, with output to the standard output stream
Serializer serializer = processor.NewSerializer();
serializer.SetOutputWriter(Console.Out);
// Transform the source XML and serialize the result document
transformer.SchemaValidationMode = SchemaValidationMode.Strict;
transformer.ApplyTemplates(File.OpenRead("po.xml"), serializer);
}
catch (Exception e)
{
Console.WriteLine(e);
Console.WriteLine("Schema compilation failed with " + compiler.ErrorList.Count + " errors");
foreach (StaticError error in compiler.ErrorList)
{
Console.WriteLine("At line " + error.LineNumber + ": " + error.Message);
}
}
and an XSLT file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text" />
<xsl:import-schema schema-location="file:///C:/Users/m_r_n/source/repos/SaxonEEExample/ValidateXslt/po1.xsd" />
<xsl:template match="schema-element(PurchaseOrder)">
<xsl:for-each select="item">
<xsl:value-of select="@id" />: <xsl:value-of select="title" />
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="*">
<xsl:message terminate="yes">Source document is not a purchase order
</xsl:message>
</xsl:template>
</xsl:stylesheet>
If I change the match to
<xsl:template match="schema-element(PurchaseOrder1)">
then this will correctly report an error
At line 8: There is no declaration for element <PurchaseOrder1> in an imported schema
Brilliant.
If I change that back and amend the for-each line to
<xsl:for-each select="item1">
then oxygen editor (using Saxon EE), correctly reports a warning for this line
The complex type of element PurchaseOrder does not allow a child element named item1
yet my C# code, will happily compile it and execute it (outputting an empty string).
How do I get the saxon compiler to report warnings? What is Oxygen doing that my code doesnt do?