RE: [xsl] Flagging for No records found?

Subject: RE: [xsl] Flagging for No records found?
From: "Kenny Akridge" <kakridge@xxxxxxxxxxxxx>
Date: Wed, 11 Feb 2004 03:13:17 -0500
It's tough to say for certain that this code will work without seeing
your $product variable, but this should work.  I would recommend getting
the count before you actually do the for-each loop.  You can branch and
just display 'no records found' if you're logic is not met.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:template match="/">
		<xsl:variable name="product">All</xsl:variable>
		<xsl:choose>
			<xsl:when
test="count(xdql/object/content/content_chunk[product = $product]) &gt;
0 or $product = 'All'">
				<xsl:for-each
select="xdql/object/content/content_chunk">
					<xsl:sort
select="content_link"/>
					<xsl:choose>
						<xsl:when
test="((product = $product) or ($product = 'All'))">
							<!-- I need to
know if I ever got here .... -->
							<a>
	
<xsl:attribute name="href">
	
<xsl:value-of select="content_link/@ref"/>
	
</xsl:attribute>
	
<xsl:value-of select="content_link"/>
							</a>
							<br/>
						</xsl:when>
					</xsl:choose>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
		no records found
			</xsl:otherwise>
		</xsl:choose>
		<!-- Print 'no records found' if nothing passed the
;when-->
	</xsl:template>
</xsl:stylesheet>
-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Andrew
Chapman
Sent: Tuesday, February 10, 2004 6:23 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Flagging for No records found?

I am trying to implement some logic to see if my XSL code found, and
then
displayed, any records. Try as I may I cannot find a clean way to do
this. I
cannot set a flag, nor can I increment a count when I find a record so I
don't know how else to trap this. If no records meet the criteria then
I'd
simply like to output a 'No Records Found' message.

The code below is an extract from the XSL, if I don't display any
results
then at the end I want to print 'No records found'.

Any ideas? Thanks!

  <xsl:template match="/">

     <xsl:for-each select="xdql/object/content/content_chunk">

      <xsl:sort select="content_link"/>

      <xsl:choose>

       <xsl:when test="((product = $product) or ($product = 'All'))">

         <!-- I need to know if I ever got here .... -->

           <a>
            <xsl:attribute name="href"><xsl:value-of
select="content_link/@ref"/></xsl:attribute>
            <xsl:value-of select="content_link"/>
           </a>

           <br/>


       </xsl:when>
      </xsl:choose>

     </xsl:for-each>

     <!-- Print 'no records found' if nothing passed the ;when


  </xsl:template>




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


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


Current Thread