Re: How can you tell if a variable exists?

Subject: Re: How can you tell if a variable exists?
From: "Scott Sanders" <scott@xxxxxxxxxxxx>
Date: Tue, 2 Nov 1999 08:33:00 -0800
> > How can you tell if a variable exists (or rather does not exist),
without
> > erroring out of the stylesheet.
>
> Since variables have to be declared before use, how can you _not_ know
> without testing whether or not a variable exists?
>
> Either the stylesheet declares the variable, or it doesn't. I must be
> missing something?

I have an HTML search form with an <input type=text name=search>.  When the
user posts the form back to the server, the SAXON servlet adds all post
parameters to the stylesheet BEFORE processing it.  I am trying to retrieve
XML data to include in the stylesheet using the document function to
retrieve a dynamically created XML page.  Something like :
       <xsl:variable name="documentUrl">
        <xsl:value-of select="$baseUrl"/>
        <xsl:value-of select="@type"/>
        <xsl:value-of select="$actionRecords"/>?sessionid=<xsl:value-of
select="$sessionid"/>
         <xsl:if test="$search">&amp;search=<xsl:value-of select="$search"/>
         </xsl:if>
       </xsl:variable>
       <xsl:for-each select="document($documentUrl)/records/record">
        Do something here....

You can see that I am using sessionid and search as variables.  sessionid is
ALWAYS passed in to the stylesheet, but search is not passed in because it
is not returned in the HTTP POST if the input is empty.  Thus search is
'undefined'.

Scott


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


Current Thread