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 June 5th, 2008, 11:57 AM
Authorized User
 
Join Date: Jun 2008
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default for-each loop and blank values

If writing a for-each loop do you need to specify if there is no value (blank) do not return a value? In the XML sample below I have pair of artist that have values, however there is one that is blank. Do I need to account for the blank artist?

<painters>
<artist>
<Date>06032008</Date>
<name>Mr. Smith</name>
<item1>blue</item1>
<item2>red</item2>
</artist>
<artist>
<Date>06052008</Date>
<name>Mr. Jones</name>
<item1>blue</item1>
<item2>red</item2>
</artist>
<artist>
<Date></Date>
<name></name>
<item1></item1>
<item2></item2>
</artist>
</painters>


 
Old June 5th, 2008, 12:04 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

It depends on what you want to output. Can you show us the output you want to generate with your stylesheet?
You could for instance use
Code:
<xsl:for-each select="/painters/artist[*[node()]]">
to ensure your for-each processes only those artist elements that have a non-empty child element.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old June 5th, 2008, 01:04 PM
Authorized User
 
Join Date: Jun 2008
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default


06032008 Mr. Smith blue red
06052008 Mr. Jones blue red



 
Old June 6th, 2008, 08:24 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

In that case you can use the approach I suggested in my previous response:
Code:
<xsl:for-each select="/painters/artist[*[node()]]">
  <xsl:for-each select="*">
    <xsl:value-of select="."/>
    <xsl:choose>
      <xsl:when test="position() != last()">
        <xsl:text> </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>#10;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
</xsl:for-each>
--
  Martin Honnen
  Microsoft MVP - XML





Similar Threads
Thread Thread Starter Forum Replies Last Post
Forcing blank values to bottom of a sort jpullam XSLT 3 August 11th, 2008 03:36 PM
Handle Null or Blank values using xslt in csv data mums XSLT 1 April 3rd, 2008 07:30 PM
Need to concatenate values in a loop LeoMathew XSLT 6 February 14th, 2008 09:03 AM
loop values and text box values move mateenmohd Classic ASP Basics 2 April 5th, 2005 11:33 PM
Delimiter for loop that may have blank rows kwerle XSLT 2 November 26th, 2003 01:25 PM





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