[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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@xxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|