Re: [xsl] unparsed-text-available a file from the current OS directory

Subject: Re: [xsl] unparsed-text-available a file from the current OS directory
From: ac <ac@xxxxxxxxxxxxx>
Date: Sun, 29 Aug 2010 19:48:53 -0400
Hi Gerrit, Michael,

Thanks for the info.

You are right %CD% works fine, you seem to be doing ok with Win-bat files! I had to add quotes, as in ... currentdir="%CD%" but it works fine and solves this use-case.

As for the symmetry between input and output resolution, the base output uri defaults to the OS current dir, while the base input uri defaults to the stylesheet dir. which can provide an application with the knowledge of where it is executing from and the additional info seems to justify the seeming relative asymmetry especially as there are indeed other means to get the %CD%.

Thank you,
ac


One way to make the current working directory known to the stylesheet
is to pass it as a parameter:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"> <xsl:output method="text"/> <xsl:param name="currentdir" /> <xsl:variable name="current-base-uri" select="concat('file:///', replace($currentdir, '\\', '/'))" /> <xsl:template name="main"> <xsl:sequence select="unparsed-text(concat($current-base-uri, '/', 'test.txt'))" /> </xsl:template> </xsl:stylesheet>


Suppose the stylesheet is c:\otherdir\test.xsl and there's a text file test.txt with contents 'TEST' in the current working directory.

Then:

C:\Users\gerrit>type test.txt
TEST

C:\Users\gerrit>java net.sf.saxon.Transform -xsl:c:/otherdir/test.xsl
-it:main currentdir=%CD%
TEST

I'm not sure I fully understood the requirement and whether there are
more 'canonical' ways to access the CWD in XSLT processors. (And I'm
not the Windows shell expert.) But I hope it is helpful anyway.

-Gerrit


On 29.08.2010 04:53, ac wrote:
Hi,

Sorry as this must have been answered before, but I have not yet found
the info.

With
<xsl:output method="text" indent="no"/>

if I use
<xsl:result-document href="boum.txt"> ...,

By default, boum.txt seems to get written to the "current" OS directory,
but if I do
<xsl:if test="unparsed-text-available('boum.txt')"> ...
boum.txt seems to get resolved from the base-uri (e.g. the stylesheet
directory path).

How can I have boum.text resolved from the current OS directory?

The objective is for processing files in the current OS directory (e.g.
from a batch (.bat) file, available from the PATH system variable, in
command-line mode), with a single instance of the stylesheet, sitting in
some other arbitrary directory.

Thank you,
ac

Current Thread