[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: How to check for absence of a node?

Subject: RE: How to check for absence of a node?
From: Rene de Vries <RdVries@xxxxxxxxxxx>
Date: Fri, 15 Jun 2001 13:52:40 +0200
xsl test node absence
Hi Sudhir,

maybe this can help you on the way (other forummembers had to help me with the param-stuff):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	
	<xsl:template match="format">
	
		<xsl:apply-templates select="tr">
			<xsl:with-param name="thCount" select="count(/format/tr/th)"/>
		</xsl:apply-templates>
	
	</xsl:template>

	<xsl:template match="tr">
		
		<xsl:param name="thCount"/>
		
		<xsl:if test="td">
			<xsl:variable name="tdCount" select="count(td)"/>

			<xsl:if test="not($thCount=$tdCount)">
				<p>
					<xsl:text>Error: number of th and td not equal</xsl:text>
				</p>
			</xsl:if>
		
			<xsl:if test="td[text()='NA']">
				<p>
					<xsl:text>Error: one or more td contain 'NA'</xsl:text>
				</p>
			</xsl:if>

		</xsl:if>
	</xsl:template>

</xsl:stylesheet>


Greetings Rene
   { @   @ }
        ^
      \__/

"You don't need eyes to see, you need vision!"

-----Oorspronkelijk bericht-----
Van:	Sudhir Malhotra [SMTP:sudhirmalhotra123@xxxxxxxxxxx]
Verzonden:	vrijdag 15 juni 2001 8:30
Aan:	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Onderwerp:	 How to check for absence of a node?

I need help in testing my input XML for "NA" or empty response as shown.  
Please refer to the following code.

I would like to call error-template in case

A. I don't find the node "format/tr[2]/td[position()>1]", or
B. The value of format/tr[2]/td[position()>1] is "NA"

Any input will be greatly appreciated.

Thanks.

-sm

-- XML input ---
      <format>
	<tr>
	  <th>th1</th>
	  <th>th2</th>
	  <th>th3</th>
	  <th>th4</th>
	  <th>th5</th>
	  <th>th6</th>
	  <th>th7</th>
	  <th>th8</th>
	</tr>
	<tr>
	  <td>timestamp1</td>
	  <td>NA</td>
	  <td>NA</td>
	  <td>NA</td>
	  <td>NA</td>
	  <td>NA</td>
	  <td>NA</td>
	  <td>NA</td>
	</tr>
       </format>
---------------
-- XSL code ---
<xsl:template match="/">

<!-- if error tag is present, process that -->
<xsl:apply-templates select="//error"/>

<!-- else if
A. I don't find the node "format/tr[2]/td[position()>1]", or
B. The value of all td's in format/tr[2]/td[position()>1] is "NA"
call error-template -->
Don't know how to code the above conditions A and B.

<!-- else,  the input XML looks good, start processing it -->
<xsl:apply-templates select="format"/>

</xsl:template>


-------------
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com


 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.