XT mkdir function and testing its success

Subject: XT mkdir function and testing its success
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Thu, 2 Sep 1999 16:10:54 -0600
I am having trouble with XT's mkdir function and the interpretation of its
result. I'm trying to figure out if it is a bug or if I am not understanding
extension functions.

I am binding a variable named 'mkdir_success' to a result tree fragment and
then testing whether the variable "is equal to" certain strings, to produce
an appropriate status message. I am getting the result tree fragment from
this snippet of code:

<!-- make a result tree fragment containing text 'true' 'false' or
'unimplemented' -->
<xsl:variable name="mkdir_success">
	<xsl:choose>
		<!-- if extension functions are available, attempt to create
$dir -->
		<xsl:when test="extension-function-available('xtfile:mkdir')
and extension-function-available('xtfile:new')"
xmlns:xtfile="http://www.jclark.com/xt/java/java.io.File";>
			<xsl:value-of
select="xtfile:mkdir(xtfile:new(string($dir)))"/>
		</xsl:when>
		<!-- if extension functions were not available -->
		<xsl:otherwise>
			<xsl:text>unimplemented</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:variable>

If I use the instruction <xsl:value-of select="$mkdir_success"/>, I get in
the result tree a text node containing string 'true' or 'false',  depending
on whether or not the directory was created, or 'unimplemented' if the mkdir
function wasn't available. So far, so good, right?

Well, for some reason, the following tests all return false, which makes it
impossible to say that the creation of the directory succeeded:

"$mkdir_success='true'"
"string($mkdir_success)='true'"
"contains(string($mkdir_success),'true')"


So here is the output I am getting on first run-through with the stylesheet
below (assuming the directory doesn't exist beforehand):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<li>$mkdir_success was 'true'...which means creation of directory 'mydir'
failed
 (perhaps it already exists).</li>

What the ...?

-Mike


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";>

    <!-- desired output is HTML 4.0 -->
    <xsl:output method="html"/>

<!--=======================================================================-
->
    <!-- the XSL processor will begin at the root node -->
    <xsl:template match="/">
        <!-- go make a directory -->
        <xsl:call-template name="mkdir">
            <xsl:with-param name="dir" select="'mydir'"/>
        </xsl:call-template>
    </xsl:template>

<!--=======================================================================-
->
    <!-- template to make a directory -->
    <xsl:template name="mkdir">
        <!-- expected parameter: $dir (string) -->
        <xsl:param name="dir"/>
        <!-- make a result tree fragment containing text 'true' 'false' or
'unimplemented' -->
        <xsl:variable name="mkdir_success">
            <xsl:choose>
                <!-- if extension functions are available, attempt to create
$dir -->
                <!-- value-of makes the Boolean result of the evaluation of
the mkdir become a string: 'true' or 'false' -->
                <xsl:when test="extension-function-available('xtfile:mkdir')
and extension-function-available('xtfile:new')"
xmlns:xtfile="http://www.jclark.com/xt/java/java.io.File";>
                    <xsl:value-of
select="xtfile:mkdir(xtfile:new(string($dir)))"/>
                </xsl:when>
                <!-- if extension functions were not available -->
                <xsl:otherwise>
                    <xsl:text>unimplemented</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <!-- put a status message in the result tree -->
        <li>
            <xsl:text>$mkdir_success was '</xsl:text>
            <xsl:value-of select="$mkdir_success"/>
            <xsl:text>'</xsl:text>
            <xsl:text>...which means creation of directory '</xsl:text>
            <xsl:value-of select="$dir"/>
            <xsl:text>' </xsl:text>
            <xsl:choose>
                <!-- these tests of $mkdir_success convert the result tree
fragment to a string -->
                <xsl:when test="$mkdir_success='unimplemented'">
                    <xsl:text>failed (XSL processor doesn't implement the
extension function).</xsl:text>
                </xsl:when>
                <xsl:when test="$mkdir_success='true'">
                    <xsl:text>succeeded.</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>failed (perhaps it already exists).</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </li>
    </xsl:template>    

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread