How i'can Count nodes in XML?

D

Diodak

How i'can Count nodes in XML?
1. how get count nodes our base in XML
for level <txt>
<article>
<txt>
<disc>aaaaaaa</disc>
<misc>bbbbbbb</misc>
<pict>bbbbbccc</pict>
</txt>
<txt>
<disc>sssss</disc>
<misc>dddddd</misc>
<pict>ffffffff</pict>
</txt>
</article>

Please give me some example or link to this solution (TNX)
 
D

Dimitre Novatchev [MVP XML]

Diodak said:
How i'can Count nodes in XML?
1. how get count nodes our base in XML
for level <txt>
<article>
<txt>
<disc>aaaaaaa</disc>
<misc>bbbbbbb</misc>
<pict>bbbbbccc</pict>
</txt>
<txt>
<disc>sssss</disc>
<misc>dddddd</misc>
<pict>ffffffff</pict>
</txt>
</article>

Please give me some example or link to this solution (TNX)


Learn XPath and use it.

Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 
G

GIMME

Even I know that...

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:preserve-space elements="*"/>
<xsl:eek:utput method='html' encoding='ISO-8859-1' indent="yes"/>
<xsl:template match="/">
<xsl:value-of select="count(/article/txt)"/>
</xsl:template>
</xsl:stylesheet>
 
D

Diodak

*******************************************
TNX for the solution but this in IE5 don't work correctly
maybe some other solution help ?

*******************************************
 
G

Gadrin77

Diodak said:
*******************************************
TNX for the solution but this in IE5 don't work correctly
maybe some other solution help ?

*******************************************

Here some VBScript using the DOM, I got off the web.
maybe someone can translate it into XSL/XSLT. You
should be able to insert your own counter.


Private Sub Dumpnode(nodename as MSXML.IXMLDOMNode, intlevel as Integer)

Dim nodattr as MSXML.IXMLDOMNode
Dim nodchild as MSXML.IXMLDOMNode

Debug.Print Space(intlevel); nodNode.NodeName; vbTab; nodNode.nodeValue

If Not nodNode.Attributes is Nothing Then
For Each nodAttr in nodNode.Attributes
Debug.Print Space(intlevel); nodNode.NodeName; vbTab; nodNode.nodeValue
Next
End If

For Each nodChild In nodNode.childNodes
DumpNode nodChild, intLevel +1
Next

End Sub


';initially called as DumpNode DomDocument, 0
 
D

Diodak

I find other solution and this work correctly in MSIE5 ;]
//file XSL

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<script type="text/javascript">
function LICZ()
{
x=xml_base.recordset
document.write(" [ ")
document.write(x.recordcount)
document.write(" ] ")
}
</script>
</head>
<body>

<xml id="xml_base" src="file_xml.xml" async="false"></xml>
<script>LICZ()</script>

</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
D

Dimitre Novatchev [MVP XML]

Diodak said:
I find other solution and this work correctly in MSIE5 ;]
//file XSL

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

This is not XSLT but an old TR dialect that nowadays almost nobody uses.

Wake up.

<xsl:template match="/">
<html>
<head>
<script type="text/javascript">
function LICZ()
{
x=xml_base.recordset
document.write(" [ ")
document.write(x.recordcount)
document.write(" ] ")
}
</script>
</head>
<body>

<xml id="xml_base" src="file_xml.xml" async="false"></xml>
<script>LICZ()</script>

</body>
</html>
</xsl:template>
</xsl:stylesheet>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top