Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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 28th, 2008, 05:44 PM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in displaying "No Dat Available" in a loop


Hello Everyone,

I am looping through "CourtAction" node and displaying the element value simultaneously. At the same time if
value is not there it should display "No Data". Now the problem here is if there are more than one node
having no values it will display "NO Data" that many number of time which i dont prefer? Can anyone give me a
solution for this?

<xsl:for-each select="c:CourtAction">
                                    <xsl:choose>
                                        <xsl:when test='c:Disposition/c:DispositionDescriptionText!= " "'>
                                            <xsl:value-of select="c:Disposition/c:DispositionDescriptionText"/>
                                            <xsl:if test="position()!=last()">
                                                <br></br>
                                            </xsl:if>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="$NoData"></xsl:value-of><br></br>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:for-each>


Also is there a better way of writing the above loop? Say using if else?

Rakesh

 
Old July 28th, 2008, 05:57 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

You need to move the conditional outside the loop:

<xsl:choose>
<xsl:when test="c:CourtAction/c:Disposition/c:DispositionDescriptionText != "">
  <xsl:for-each select="c:CourtAction/c:Disposition/c.....
  </xsl:for-each>
</xsl:when>
<xsl:otherwise>No Data</xsl:otherwise>
</xsl:choose>

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Have a problem in For-each loop LeoMathew XSLT 2 July 16th, 2008 05:20 AM
loop problem smilesmita Pro PHP 1 November 2nd, 2007 02:15 AM
Loop problem! Please help me!! olud ASP.NET 1.0 and 1.1 Basics 2 March 19th, 2007 07:38 AM
while loop problem shoakat Classic ASP Databases 1 September 21st, 2004 03:44 PM





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