Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 12th, 2004, 01:53 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to count total number of nodes in an xml file?

Hi.

Just wondering if anyone can help me.

I need to to write a simple XSLT script which returns the total number of nodes within a sample XML file.
I tried running the following code, but it returns 30 nodes, instead of 20 for the following sample file.
Any ideas how to amend the code so it returns the correct node count?

Thanks!


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:value-of select="count(//node())"/>
    </xsl:template>
</xsl:stylesheet>


<?xml version="1.0" encoding="UTF-8"?>

<FiML version="0-7">
<fiHeader>
<fiSystemTradeIdentifier>
<fiSystemId>Test</fiSystemId>
<fiTrade>
<fiTradeId>12345678</fiTradeId>
<fiVersionNumber>1</fiVersionNumber>
<fiVersionTimestamp>2004-08-04</fiVersionTimestamp>
</fiTrade>
<fiTradeLinkId>10360614</fiTradeLinkId>
</fiSystemTradeIdentifier>
<fiSourcePartyReference href="SOURCE"/>
</fiHeader>
</FiML>



Reply With Quote
  #2 (permalink)  
Old August 12th, 2004, 03:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well, it all depends what you think a node is. The node() test matches all types of nodes, i.e. comment, PI, element and text nodes, so if you're getting the "wrong" answer, then you're using the wrong test!

I don't see how you get 30 from the sample XML you posted, nor do I see why you expect 20. I suggest you look at the alternatives to node() at http://www.w3.org/TR/xpath and decide which one(s) you want to count.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to Count number of lines in a file lawsoncobol Access VBA 2 July 19th, 2007 04:28 AM
count the number of nodes in an XML doc crmpicco Perl 3 December 8th, 2006 08:30 AM
count the TOTAL number of segments crmpicco Classic ASP Basics 2 February 1st, 2005 05:03 AM
Getting Total Page Count eman2a Crystal Reports 0 August 11th, 2004 10:53 AM
Sub Total, Count discriminating dkaco BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 July 23rd, 2004 12:04 PM



All times are GMT -4. The time now is 02:54 PM.


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