5

my input file:

<folders>
    <folder name="a" level="1" metadataFile="LVM20metadata.tsv">
        <subfolder name="a/er" level="2" filter="no" />
        <subfolder name="a/ir" level="2" filter="yes" />
        <subfolder name="a/ar" level="2" filter="no" />
        <subfolder name="a/or" level="2" filter="yes" />
    </folder>
    <folder name="b" level="1" metadataFile="LVM21metadata.tsv">
        <subfolder name="b/er" level="2" filter="no" />
        <subfolder name="b/ir" level="2" filter="yes" />
        <subfolder name="b/ar" level="2" filter="no" />
        <subfolder name="b/or" level="2" filter="yes" />
    </folder>
</folders>

my stylesheet:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions " exclude-result-prefixes="fn xs">

    <xsl:template match="/">

        <xsl:apply-templates/>


    </xsl:template>

<xsl:template match="folders">
<xsl:apply-templates/>
</xsl:template> 

<xsl:template match="folder">
<xsl:result-document method="xml" standalone="yes" href="{@name}.xml">
<hello></hello>
</xsl:result-document>
</xsl:template>

</xsl:stylesheet>

It doesn't create the two result-documents. Why is that? (using saxon9he)

Shouldn't this create two XML documents with the names a.xml and b.xml?

Abel
  • 56,041
  • 24
  • 146
  • 247
user3813234
  • 1,580
  • 1
  • 29
  • 44
  • The XSLT in your question is not well-formed - you have an opening `` and a closing ``. Does it work if you fix those to match (either will work, but they both need to be the same)? – Ian Roberts Mar 16 '15 at 12:58
  • sorry, something went wrong when I inserted the code. I edited my question and it now shows my current stylesheet – user3813234 Mar 16 '15 at 13:01
  • 1
    If you run Saxon 9 from the command line, use the `-t` option to get details about what happens and where, if any, result files are written. – Martin Honnen Mar 16 '15 at 13:39
  • Interesting. Anything other than `a.xml` works as a file name. – Mathias Müller Mar 16 '15 at 15:03
  • I tried your samples on Windows with Saxon 9.6 HE and the `-t` option, it explains `Writing to file:/C:/Users/UserName/Documents/xslt/a.xml Writing to file:/C:/Users/UserName/Documents/xslt/b.xml`, so the two files are created, each containing ``. Does that not work for you? – Martin Honnen Mar 16 '15 at 15:22
  • @MartinHonnen I tested with Oxygen/Saxon-EE 9.5.1.7 - if the file name for `xsl:result-document` is "a.xml", the document does not appear in the file system. Any other string works, unfortunately there is no `-t` option in Oxygen. – Mathias Müller Mar 16 '15 at 15:25
  • @user3813234, are you also using Saxon inside Oxygen, like Mathias? Then I would suggest you tag the question as oxygen as well, perhaps the problem only occurs with Saxon in Oxygen. Although not being able to write a file named `a.xml` sounds like a very strange error to me. – Martin Honnen Mar 16 '15 at 17:14
  • Hello! Thanks for your replies! I am using Altova with Saxon. I added the -t option. The documents get created but for some reason written to my AppData/Local/Temp folder. Do you happen to know whether that's a Saxon or an Altova thing? – user3813234 Mar 19 '15 at 09:36
  • @user3813234, I am not familiar with using Saxon and Altova and how to set it up to have the output in a particular directory. – Martin Honnen Mar 20 '15 at 09:23
  • alright, will check elsewhere. Thanks though!! – user3813234 Mar 20 '15 at 12:24

1 Answers1

1

This is actually a known feature (or bug, if you prefer) if you run your stylesheet from oXygen, or in your case Altova. I am not sure if present versions still have this "feature", but it worked as follows:

  • If there is no primary result document (i.e., an empty sequence is generated)
  • And there is a secondary result document (i.e. with xsl:result-document)
  • Show the first such result documents in the user interface
  • Let any other result documents be created normally

I believe this is because the tools use an UriResolver of some kind to redirect the primary result. The UriResolver is not called if there is no output, but is then called by the next secondary output, resulting in this behavior. This is the reason why this file ends up in the temporary file location of your system (you will find the primary output document there with "normal" transforms as well).

Whenever I encounter this and I do not like the behavior, the simple solution is to create a dummy primary result document. In your case this can be something like:

<xsl:template match="/">
    <root>Primary result doc, please ignore, see other files.</root>
    <xsl:apply-templates/>
</xsl:template>

I believe there is a system property or environment variable that you can use to interrogate whether or not it is running in the UI, or in the absence thereof, add a parameter to the invocation commandline that sets a static parameter (unfortunately, this only works in XSLT 3.0), which you can use in use-when.

Abel
  • 56,041
  • 24
  • 146
  • 247