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

Problem with empty element check !

Subject: Problem with empty element check !
From: "Shamik Bandopadhyay -X \(sbandopa - TCS at Cisco\)" <sbandopa@xxxxxxxxx>
Date: Tue, 11 Jul 2006 03:03:13 +0530
xsl check for empty element
 Hi,

  I'm facing an issue with an empty element check using XSLT.Here's my
sample XSLT.I'm checking whether <money> has a value,id yes I'm
printing,else skip.But,even if there's no value or the tag doesn't
exist,the control is getting inside the xsl:if check and printing the
bullets.Any pointers will be appreciated. Here's the xsl I'm using.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<html>
			<body>
				<h2>My CD Collection</h2>
				<table border="1">
					<tr bgcolor="#9acd32">
						<th>Title</th>
						<th>Artist</th>
					</tr>
					<xsl:for-each
select="catalog/cd">
						<xsl:variable
name="empty_string" select="money"/>
					        <xsl:if
test="not($empty_string = normalize-space(.))">
							<tr>
								<td>

<ul>

<li>

<xsl:value-of select="money"/>

</li>

</ul>
								</td>

<xsl:value-of select="name()"/>
							</tr>
						</xsl:if>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

Here's the sample XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>
<catalog>
  <cd>
     <title>Empire Burlesque</title>
     <artist>Bob Dylan</artist>
	 <price>
	 	<currency>Pound</currency>
	 </price>
  </cd>
  <cd>
     <title>Hide your heart</title>
     <artist>Bonnie Tyler</artist>
     <price>
	 	<currency>Pound</currency>
	 </price>
	 <money>22</money>
  </cd>
  <cd>
     <title>Greatest Hits</title>
     <artist>Dolly Parton</artist>
     <price>
	 	<currency>Pound</currency>
	 </price>
	 <money>33</money>
  </cd>
  <cd>
     <artist>John Denver</artist>
     <price>50</price>
	 <money></money>
  </cd>
</catalog>


Thanks

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.