XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Todd EischeidSubject: 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:

<?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]" mode="found"></xsl:apply-templates>
<xsl:apply-templates select="/glossary/definition" mode="not-found"></xsl:apply-templates>
</body>
</html>
</xsl:template>

<xsl:template match="/glossary/definition[@name=$paramVal]" mode="found">

<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:template match="/glossary/definition" mode="not-found">

<xsl:if test="count(/glossary/definition[@name=$paramVal])&lt;1">

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

</xsl:template>

</xsl:stylesheet>

Postnext
James DurningSubject: 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>

Posttop
Todd EischeidSubject: displaying specific html when the result of a query has count = 0
Author: Todd Eischeid
Date: 02 Oct 2007 08:42 PM
Thank you so much for the help. Your revised xsl works great!

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.