Subject:displaying specific html when the result of a query has count = 0 Author:Todd Eischeid Date:30 Sep 2007 10:43 AM
Hi All,
I have a simply xml file that is basically a glossary, and I supply a term to it and I have an XQuery string that does a lookup on the term. I'm using an xsl style sheet to format the results for the browser window.
I thought it would be simple (and it may be) to print a single 'term not found' type of message to the screen if the term was not in the xml glossary file. If the term *is* in the xml file, the code works ok, but I cannot get the desired result when the term is not in the file. Seems like this should be simple, but I'm just stumped. Any help is greatly appreciated.
Below is my xsl file, I am supplying the term via setting the parameter 'paramVal' to the desired term:
Subject:displaying specific html when the result of a query has count = 0 Author:James Durning Date:02 Oct 2007 11:02 AM
The problem is that if you use apply-templates, you'll be applying the templates once for each definition. Not only is it slow, but you'll get the results over and over.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="paramVal"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="/glossary/definition[@name=$paramVal]"/>
<xsl:if test="not(/glossary/definition[@name=$paramVal])">
<h3 style="margin-top:0em;margin-left:0px;">
<xsl:value-of select="@name"/>
</h3>
<p style="color:gray;">This term could not be located in the glossary.</p>
</xsl:if>
</body>
</html>
</xsl:template>
<xsl:template match="/glossary/definition[@name=$paramVal]">
<h3 style="margin-top:0em;margin-left:0px;">
<xsl:value-of select="@name"/>
</h3>
<p><xsl:value-of select="."/></p>
<p><xsl:value-of select="last()"/></p>
</xsl:template>
</xsl:stylesheet>