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 November 25th, 2003, 02:57 PM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delimiter for loop that may have blank rows

I have data that looks like this:
<parent>
 <child>
  <info>bar</info>
 </child>
 <child>
  <data>foo</data>
  <info>bar</bar>
 </child>
 <child>
  <info>bar</info>
 </child>
 <child>
  <data>foo</data>
  <info>bar</bar>
 </child>
</parent>

Really, the info nodes are more complex and have their own template.

In short, what I'd like to do is output all the data and info for any children that have a data node, with a delimiter between:
foo
bar
---
foo
bar

So I want the data, followed by the info, followed by a delimiter IF there is another child node with data. The problem is that any child node may or may not have data. This includes the first [n] children, the last [n] children, and any groups of children in the middle. I was thinking that following-sibling:: was going to solve my problem, but that fails if there is a gap anywhere but the end.

How can this be done?

TIA,
Kurt

 
Old November 26th, 2003, 02:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

(not tested)

Code:
  ...
  <xsl:template match="/">
    <xsl:apply-templates select="parent/child[data]"/>
  </xsl:template>  
 
  <xsl:template match="child[data]">
    <xsl:value-of select="data"/><br/>
    <xsl:value-of select="info"/><br/>
    <xsl:if test="following-sibling::child[data]">
      ---<br/>
    </xsl:if>
  </xsl:template>
  ...
Regards,
Armen
 
Old November 26th, 2003, 01:25 PM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That does the trick, sure enough.

Thanks!
kwerle






Similar Threads
Thread Thread Starter Forum Replies Last Post
for-each loop and blank values Navy1991_1 XSLT 3 June 6th, 2008 08:24 AM
blank rows in database MADMACZ C# 3 June 23rd, 2006 12:07 PM
blank rows in database MADMACZ C# 0 June 1st, 2006 10:44 AM
Comma Delimiter / Text Qualifier pearce64 Excel VBA 0 October 25th, 2005 04:57 PM
Automatically Finding and Deleting Blank rows Romulus Excel VBA 3 October 18th, 2003 09:04 PM





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