[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Checking if a file exists

Subject: Re: Checking if a file exists
From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Apr 2024 23:40:49 -0000
Re:  Checking if a file exists
On Thu, 18 Apr 2024 at 23:58, dvint dvint@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> I'm trying to stop the result-document() from writing to the file more
> than once. I had moved from the file:exist() because I need to use the
> saxon-pe to use it, but oxygen ant transformation only allows the use of
> the HE edition.
>
> So am I right in thinking there may be ae sequencing/file writing issue
> here and the error is triggered because the file hasn't been written yet,
> but the result-document knows it is in memory?
>

you haven't really given enough information to answer,

even if you use the same URL if you test doc-available($newFile)   then
xsl:result-document href="{$newFile} can fail as the doc-available test
checks that the url corresponds to a well formed xml document and the
xsl:result-document fails if that URL has already been used to write from
the same stylesheet. These conditions are only indirectly related, and in
the code you show, you test doc-available($newFile)  but write to
{$rename-outPath}/{$newName}.dita  which may or may not be the same file
and may or may not be well formed, depending on code not shown.

You also didn't show the xsl context, it's best to consider a for-each as
executed in parallel so you can't reliably a test such as you show to test
if some other iteration of the loop has already written the file.

Normally (or at least, sometimes) it's best to arrange to avoid writing the
same file twice by constructing a sequence that has no duplicates and then
iterating over that list.

David

>
>
>
> Sent from my Verizon, Samsung Galaxy smartphone
>
>
> -------- Original message --------
> From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
> Date: 4/18/24 3:38 PM (GMT-08:00)
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  Checking if a file exists
>
> On Thu, 2024-04-18 at 22:28 +0000, dvint@xxxxxxxxx wrote:
> > I need to take a list of XML files and rename them based upon values
> > provided by the writer. I know that my list has duplicate name tokens
> > for different files in the list. I do get duplicate names when
> > generated.
> >
> > I'm trying to trap this situation and handle this while creating the
> > files, I have a template with this:
> >
> > ...
> >
> > '<xsl:value-of select="$newFile"/>' found '<xsl:value-of
> > select="doc-available($newFile)"/>'
>
> doc-available is not the same as file:exists() - it will only be true
> if the document could be read successfully with doc() (and of course to
> dettermine this, the XSLT processor effectively does a doc() behind the
> scenes, and then probably has to keep it in memory in case it changed
> externally).
>
> Also make sure your XSLT didn't create the document using result-
> document... You can't write to the same URI more than once in the same
> XSLT run.
>
> Without seeing the exact error message it's hard to be sure.
>
> liam
>
> --
> Liam Quin, https://www.delightfulcomputing.com/
> Available for XML/Document/Information Architecture/XSLT/
> XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
> Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/2739265> (by
> email <>)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.