This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: testing for existence of variables?


Matthew,

>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:if>

or

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

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:choose>
    <xsl:when test="//user">
      content for known users
    </xsl:when>
    <xsl:otherwise>
      content for unknown users
    </xsl:otherwise>
  </xsl:choose>

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,

Jeni

Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 • Fax 0115 9061304 • Email
jeni.tennison@epistemics.co.uk



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]