Re: [xsl] Keeping result-document() from writing to a file more than once?

Subject: Re: [xsl] Keeping result-document() from writing to a file more than once?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Apr 2019 22:16:42 -0000
The rules are designed, in principle, to ensure that there is no dependency on
order of execution, and in particular, that a URI that is written to during a
transformation can never be read during the same transformation, either before
or after the writing (because there is no mutable state, therefore no "before"
and "after", in a functional world). If you use doc-available() on a
particular URI, and xsl:result-document on the same URI, then either
doc-available() should return false, or xsl:result-document should fail.

This doesn't seem to be what you are observing, which could indicate
non-conformant behaviour.

But basically, what you are doing shouldn't work. It should not be possible to
detect any change in the state of persistent filestore during the course of a
transformation by calling doc-available(), or otherwise (except by use of
extension functions, which don't have to follow any rules).

Solving your problem (preventing result-document from writing to a file more
than once) has to be done in a different way: it's essentially the same as any
other de-duplication or grouping task. You have to find all the references to
a given URI and process them as a group. You can't do it (unless you cheat) by
peeking into filestore to see if it has changed.

Michael Kay
Saxonica

> On 18 Apr 2019, at 22:56, dvint@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> I'm processing some DITA xml files with XSLT. I'm reading these files and
where they have a conref into some other content (think xinclude) that is
included in the current file. There may be multiple things shared out from one
large file (topic). I want to make a new file for each of the shared pieces.
>
>  More than one file can reference exactly the same content, so after
processing all these files I want a single file representing the shared
content. It is this multiple references to the same content that causes the
duplication of the file that the result-document() function doesn't like. this
is the code that I have for detecting this situation:
>
>  <xsl:variable name="newFile" select="concat($srcFile, '-', $target,
'-output.dita')" />
>
>
>
>  NEW FILE <xsl:value-of select="$newFile"/>
>
>  Doc available: <xsl:value-of select="doc-available($newFile)"/>
>
>
>  <xsl:if test="not(doc-available($newFile))"
>
>  CREATE FILE NOW
>
>  <xsl:result-document method="xml" href="{$newFile}" indent="yes">
>  <referable-content id="ikj1555615661716" xml:lang="en-us">
>  <titler>efereable test</title>
>  <rcbody>
>  <xsl:copy-of select="document($srcFile)//*[@id = $target]"/>
>  </rcbody>
>  </referable-content>
>  </xsl:result-document>
>
>  </xsl:if>
>
>
>
>
>
>  Here are a series of messages created as i process the files. Notice that
the first message correctly identifies the file
"conref-para_content.dita-simpletable_nohead-output.dita" as not existing and
produces output. If you then look at the last one you will see the same file
being referenced and tries to write to the file again. But in other places you
see the test working properly and not creating a new file:
>
>
>
>
>
>  file 'conref-para_content.dita'
>  NEW FILE
/Users/danvint/pubsrc-other/formatting-sample/conref-para_content.dita-simple
table_nohead-output.dita
>  Doc available: false'
>
>  CREATE FILE NOW
>
>  file 'conref-para_content.dita'
>  NEW FILE
/Users/danvint/pubsrc-other/formatting-sample/conref-para_content.dita-simple
table_head-output.dita
>  Doc available: true'
>
>  file 'conref-para_content.dita'
>  NEW FILE
/Users/danvint/pubsrc-other/formatting-sample/conref-para_content.dita-table_
head-output.dita
>  Doc available: true'
>
>  file 'conref-para_content.dita'
>  NEW FILE
/Users/danvint/pubsrc-other/formatting-sample/conref-para_content.dita-table_
nohead-output.dita
>  Doc available: true'
>
>  file 'conref-para_content.dita'
>  NEW FILE
/Users/danvint/pubsrc-other/formatting-sample/conref-para_content.dita-simple
table_nohead-output.dita
>  Doc available: false'
>
>  CREATE FILE NOW
>
>
>
> I believe the doc-available() reads the file to be XML. So when the script
stops there is a file in the OS but it is empty due to the second write
failing. Running this in oXygen I get the results of what should have been
written showing up in a window. I cut and pasted that content into the empty
file and reran it. Processing got further along and stopped on a second file
with the same message. I did the same thing, with the new content in this
second file and it now runs to completion if all the files exist.
>
> If I delete all the files that were generated, I'm back to the same problem.
Is there some delay in writing the output that I should  be accounting for? Is
there a sleep() function in XSLT or something to cause a delay or flush the
buffer?
>
>  Any ideas on what I can check?
>
>
>
>  ..dan
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

Current Thread