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 March 30th, 2005, 12:54 PM
Registered User
 
Join Date: Nov 2004
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
 
Old March 30th, 2005, 01:01 PM
Registered User
 
Join Date: Nov 2004
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.

 
Old March 30th, 2005, 01:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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