Re: testing for existence of variables?

Subject: Re: testing for existence of variables?
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2000 10:17:32 +0100

>What I want to know is, can I check for the existence of the <user> 
>information and display some HTML if it exists, and otherwise present 
>alternate HTML? Or should this check be done on the server side in the 
>scripting layer instead?

You can do this within an XSLT stylesheet.  There are a couple of elements
that enable you to conditionally construct results:

  <xsl:if test="condition">
    result if the condition is true


    <xsl:when test="condition1">
      result if condition1 is true
    <xsl:when test="condition2">
      result if condition2 is true
      result if no conditions are true

So, in your case, you want to test if the XML document contains a 'user'
element, to output one set of HTML if it is, and another if it isn't:

    <xsl:when test="//user">
      content for known users
      content for unknown users

Note: I don't know where in your XML document this 'user' element appears,
and it would be better if you can construct a direct path to it, to save
the XSLT processor having to search every descendent of the root node.

I hope this helps,


Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email

 XSL-List info and archive:

Current Thread