1

the xsl code is the following

<xsl:template match="/">
  <xsl:for-each select="/t:Flow/t:AccountingRecords/t:AccountingRecord">
    <xsl:result-document method="xml" href="UBL-invoice.2.1-{t:Reference}-output.xml">
      <xsl:apply-templates select="."/>
    </xsl:result-document>
  </xsl:for-each>
</xsl:template>

this runs well from the command line using transform

now I try do use it from a .net app and I get the following error:

$exception {"The system identifier of the principal output file is unknown"} Saxon.Api.DynamicError

If I change my code to

<xsl:result-document method="xml" href="file:///d:/temp/UBL-invoice.2.1-{t:Reference}-output.xml">
  <xsl:apply-templates select="."/>
</xsl:result-document>

then I get my files.

My question is: is there a way to work with relative path from an app, or must I add a dir parameter to my xsl ?

My code is quite the one from the samples

Processor proc = new Processor();
var comp = proc.NewXsltCompiler();
Xslt30Transformer exe = comp.Compile(new Uri("file:///" + System.IO.Path.GetFullPath("./Styles/style.xslt"))).Load30();

 DocumentBuilder builder = proc.NewDocumentBuilder();
 builder.BaseUri = new Uri("file:///" + System.IO.Path.GetFullPath("./ar2.xml"));

 XdmNode inp = builder.Build(System.IO.File.OpenRead(System.IO.Path.GetFullPath("./ar2.xml")));

 Serializer serializer = proc.NewSerializer();
 serializer.SetOutputWriter(Console.Out);

 // Transform the source XML and serialize the result document
 exe.ApplyTemplates(inp, serializer); // < ==== Exception here
tschmit007
  • 7,559
  • 2
  • 35
  • 43

1 Answers1

1

Set the BaseOutputURI property on the Xslt30Transformer object. This will be used as the base URI for resolving the relative URI appearing in xsl:result-document/@href.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • it works with `exe.BaseOutputURI = "file:///" + Directory.GetCurrentDirectory().Replace("\\", "/");` The prefix and replace are necessary. – tschmit007 Feb 22 '19 at 18:11
  • To get a URI from a filename on .NET, see https://stackoverflow.com/questions/1546419/convert-file-path-to-a-file-uri – Michael Kay Feb 23 '19 at 08:41