• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

using xsl:for-each tag in xsl file

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,
I am new to XML and XSLT and I am learing them.

If for a particular column we have sub rows then how can we get to show them in an html page

For example, consider these four columns..

name age gender children


in my xml i have tags as
<Family>
<name>Suresh</name>
<age>30</age>
<gender>Male</gender>
<children>
<name> Sruthi</name>
<age> 8</age>
<gender> Female</gender>
</children>
<children>
<name>Sraavya</name>
<age>4 </age>
<gender> Female</gender>
</children>
<children>
<name>Sravanthi</name>
<age>2 </age>
<gender>Female </gender>
</children>
</Family>
<Family>
<name>Nitin</name>
<age>38</age>
<gender>Male</gender>
<children>
<name> Shanthi</name>
<age> 15</age>
<gender> Female</gender>
</children>
<children>
<name>Sheetal</name>
<age>12 </age>
<gender> Female</gender>
</children>
<children>
<name>Vidya</name>
<age>9</age>
<gender>Female </gender>
</children>
<children>
<name>kaavya</name>
<age>6 </age>
<gender> Female</gender>
</children>
<children>
<name>Neeta</name>
<age>3</age>
<gender>Female </gender>
</children>
</Family>

The output in the html file after formatting in the xsl file Should be as

name age gender children

Suresh 30 Male Sruthi
Sraavya
Sravanthi

Nitin 38 Male shanthi
sheetal
vidya
kaavya
Neeta
Please note that the children names appear one after the other in the next line below the children column

And my xsl file is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table>
<xsl:for-each select="details/family">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="gender"/></td>
<xsl:for-each select="children">
<td><xsl:value-of select="name"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

When i am doing it, i am getting the output as,

name age gender children

Suresh 30 Male sruthi sraavya Sravanthi
Nitin 38 Male shanthi sheetal vidya kaavya Neeta

Here i am getting the children names in the same line.

Can anyone Pl explain how to get the desired output

Thanks in Advance.
[ June 07, 2005: Message edited by: vishme vish ]
 
Ranch Hand
Posts: 1241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so you want each of the children to be on a separate line? The first thing you need to do is to stop the parents from being in the same table row as the children, so you'll need to end the table row after the parent row. Next you want the children to each appear on their own row, so try wrapping their cell elements in row elements. Thirdly you wanted the children to appear in the third "children" column. One way to do that is to add some empty cells for the other two columns.

To put it all together, try replacing:

with

[ June 08, 2005: Message edited by: Dave Lenton ]
 
vishme vish
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dev for the reply.

I could able to get the desired output.

Thanks
Vishme
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic