Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 30th, 2005, 12:54 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdavisiii
Default xsl:if question

I solved it, I was working in the wrong place in the code. I have been staring at this stuff too long.

I am try filter out <name> elements that are blank.

I have the following xml

<logicresponse>
<results>
<resultslist xmlns:fo="http://www.w3.org/1999/XSL/Format">
<contact><name>Bill Smith</name>
<phone>(603)555-8638 14</phone>
</contact>
<contact>
<name>John Harrington</name>
<phone>(603)555-8638</phone>
</contact><contact>
<name>Matt Hill</name>
<phone>(603)555-8638</phone>
</contact>
<contact><name>Ron Davis</name>
<phone>(603)555-8638 12</phone>
</contact>
<contact>
<name>Steve Jones</name>
<phone>(603)555-8638</phone>
</contact>
<contact>
<name> </name>
<phone> </phone>
</contact>
<contact>
<name> </name>
<phone> </phone>
</contact>
<contact>
<name> </name>
<phone> </phone>
</contact>
</resultslist>
</results>
</logicresponse>



I want to produce html from the xml but do not want any contact elements that contain no data.

I have tried the following:

    <xsl:for-each select="/logicresponse/results/resultslist/contact">

    <xsl:if test="name != ' '">

        <tr>
         <td><a href="{$l}EditAccount&amp;id={position()}" class="calltoday"><xsl:value-of select="company" /></a></td>
        </tr>
        <tr>
         <td><xsl:value-of select="name" /></td>
        </tr>
        <tr>
         <td><xsl:value-of select="phone" /></td>
        </tr>
        <tr>
         <td><xsl:value-of select="city" /></td>
        </tr>
    
    </xsl:if>

     </xsl:for-each>

The result is the outputed html table has a bunch of blank rows. What am I missing here?

Thanks
Ron
Reply With Quote
  #2 (permalink)  
Old March 30th, 2005, 01:01 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdavisiii
Default

nevermind I was working in the wrong place. Sometimes I stare at this stuff to long and go blind.

Reply With Quote
  #3 (permalink)  
Old March 30th, 2005, 01:40 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Perhaps you are using Microsoft's XSLT processor, which contrary to the XSLT specification removes white-space-only text nodes: this means that your <name> </name> becomes <name></name>.

Try testing xsl:if test="normalize-space(name)".

Also, if the entire body of a for-each consists of an xsl:if, then you can put the condition into the select expression as a predicate:

xsl:for-each select="/a/b/c/d[normalize-space(name)]">



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl question for new user MHTL XSLT 4 May 13th, 2008 10:01 PM
XSL newbie question Someone2006 XSLT 4 October 10th, 2006 07:20 AM
xsl question bluisana XSLT 7 September 15th, 2005 01:34 AM
xsl:sort Question kwilliams XSLT 6 July 18th, 2005 08:39 AM
XSL processing question.. eladner XSLT 1 August 24th, 2004 07:58 AM



All times are GMT -4. The time now is 01:04 PM.


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