1

I am using XSLT3 as provided in Saxon to convert a single input XML file to a set of output files. All these output files are conceptually equivalent. Each output file is declared via the result-document directive, as explained on https://www.w3.org/TR/2007/REC-xslt20-20070123/#element-result-document.

In this case, I don't need any main output, but Saxon is still creating such output file. Is it somehow possible to disable the main output in XSLT3 or Saxon?

I could use result-document for all desired output files, except the last one, and just use the main output for that one - but that feels odd.

  • 2
    How do you use Saxon, show us your command line or your (Java?/.NET?) code. How does a minimal XSLT code look, does the stylesheet produce any output in templates that don't use `xsl:result-document`? โ€“ Martin Honnen Sep 16 '19 at 12:45

1 Answers1

1

It's a good question. XSLT 2.0 had a very complicated rule (in ยง2.4): An implicit result tree is also created when the result sequence is empty, provided that no xsl:result-document instruction has been evaluated during the course of the transformation. In this situation the implicit result tree will consist of a document node with no children.

Interpreting "creating a result tree" as meaning that the corresponding serialised output file is written to filestore, this means that when the principal result tree is empty, the corresponding output file is written if and only if there are no secondary output files. Which is (I think) the effect that you are asking for.

This rule became increasingly unwieldy in XSLT 3.0 because of the greatly extended ways of invoking a stylesheet (e.g by calling an initial public function), and it was therefore dropped; and Saxon followed suit.

You can certainly avoid the file being written by supplying a result or destination that discards it rather than writing it to filestore (for example, in s9api, an XdmDestination). Achieving the same thing from the command line is not so easy; in fact, I'm not sure it can be done without writing some Java or C# code somewhere.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • 1
    I guess for discarding the primary output it doesn't hurt to mention `NullDestination` (http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/NullDestination.html) as well. As for from the command line, I guess that is dependent on the OS and shell, https://stackoverflow.com/questions/313111/is-there-a-dev-null-on-windows suggests in a Windows command you can use `NUL` or `NUL:` as a kind of `/dev/null` device. โ€“ Martin Honnen Sep 16 '19 at 15:49
  • 1
    Yes, I forgot about `NullDestination`. The problem with sending to `/dev/null` is that the base URI of the primary output is used for resolving relative URIs in `xsl:result-document` โ€“ Michael Kay Sep 16 '19 at 16:48