Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange behavior with xsl:result-document from within Altova XML with Saxon

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?

like image 607
user3813234 Avatar asked Nov 10 '22 17:11

user3813234


1 Answers

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.

like image 78
Abel Avatar answered Dec 02 '22 07:12

Abel