Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2006, 04:31 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem -- Empty element check !

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>
                                    [list]
                                        <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

 
Old July 10th, 2006, 04:37 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's bad etiquette to post the same question on more than one forum simultaneously. It means that people waste their time responding to you when you've already got an answer.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 10th, 2006, 04:58 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not sure I got ur point. And I surely don't second ur opinion in posting the same question to different forums.Sounds like u shudn't refer to multiple books when u get information in one.People do post their questions in different forums to get better views and answers,as not all the people in the world are necessarily subcribed to one single forum,except ofcourse,few guys like u.And if u've already figured out that its a waste of time to go thru the same mail, then simple don't respond,no one needs ur word of wisom.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset Empty Check Coby Access VBA 2 April 27th, 2007 04:09 PM
best way to check for variable being empty crmpicco Classic ASP Basics 3 March 28th, 2006 12:11 PM
How do I test for an empty array element kmoran Excel VBA 1 October 8th, 2004 03:34 AM
check if empty hosefo81 Javascript How-To 12 March 9th, 2004 08:43 AM
How to check if collection is empty Ciarano Beginning VB 6 2 March 5th, 2004 08:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.