Subject: Delimiter for loop that may have blank rows
Posted By: kwerle Post Date: 11/25/2003 1:57:14 PM
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

Reply By: armmarti Reply Date: 11/26/2003 1:12:34 AM
(not tested)


  ...
  <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
Reply By: kwerle Reply Date: 11/26/2003 12:25:08 PM
That does the trick, sure enough.

Thanks!
kwerle


Go to topic 6769

Return to index page 997
Return to index page 996
Return to index page 995
Return to index page 994
Return to index page 993
Return to index page 992
Return to index page 991
Return to index page 990
Return to index page 989
Return to index page 988