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 November 10th, 2006, 04:03 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to count the child node

Hi All

How can I count the total no.of children in XSLT from the below xml file??

thx
suri

XML FILE
========

<main>
    <father>
        <child>sam</child>
        <child>debi</child>
    <father>
    <father>
        <child>donna</child>
        <child>kathy</child>
        <child>usher</child>
    <father>
    <father>
    <father>
    <father>
        <child>donna</child>
    <father>
</main>
 
Old November 10th, 2006, 04:12 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I guess count(//father/child) should give me the result.

But, I want to set a counter after displaying the every 5 children name I need to display the dotted line '--------'

thx for the help
suri

 
Old November 10th, 2006, 04:45 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

count(//child)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 10th, 2006, 04:46 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

>But, I want to set a counter after displaying the every 5 children name I need to display the dotted line

<xsl:for-each select="//child">
  <xsl:copy-of select="."/>
  <xsl:if test="position() mod 5 = 1">---------</xsl:if>
</xsl:for-each>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 10th, 2006, 04:47 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for not being clear.

How can I display only first childeren names?

thx
Suri

 
Old November 10th, 2006, 04:48 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Again there was a typo...Sorry about that...

My question was How can I show first 5 childeren's names.

thx

 
Old November 10th, 2006, 04:51 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got you....

Thx alot Michael Kay
suri






Similar Threads
Thread Thread Starter Forum Replies Last Post
Select correct child node richieWolf XSLT 4 September 24th, 2008 08:53 AM
Process all nested child node tims XSLT 4 April 8th, 2008 07:45 AM
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Child Node Output Neal XSLT 0 June 7th, 2006 03:14 AM





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