Hi,
How can I find the number of nodes in the node-set. Here in the below document
I want to find the number of nodes in DocumentList element. Am new to Xpath. Can anyone please help me out?

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

<ProcessData>

<SessionBeginTime>2009-07-14 13:24:28.218</SessionBeginTime>

<ServerResponse>

<Code>226</Code>

<Text>226 Transfer OK</Text>

</ServerResponse>

<DocumentList>

<DocumentId>dev4206:80f4cb:12279c825a4:176f</DocumentId>

<DocumentId>dev4206:80f4cb:12279c825a4:1773</DocumentId>

<DocumentId>dev4206:80f4cb:12279c825a4:1776</DocumentId>

</DocumentList>

<Prev_NotSuccess_Adv_Status>Primary document is null</Prev_NotSuccess_Adv_Status>

</ProcessData>

Thanks in advance

count(//DocumentId)

Thanks for your reply.
I've used the same, count(//DocumentId), but it's not working
Am using mozilla firefox browser. Tried in IE also, but no result.
Can anyone please help me out?

Thanks in advance........

I do not what is the Probelm

an Example

xml with xsl

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="process.xsl"?>
<ProcessData>
	<SessionBeginTime>2009-07-14 13:24:28.218</SessionBeginTime>
	<ServerResponse>
		<Code>226</Code>
		<Text>226 Transfer OK</Text>
	</ServerResponse>
	<DocumentList>
		<DocumentId>dev4206:80f4cb:12279c825a4:176f</DocumentId>
		<DocumentId>dev4206:80f4cb:12279c825a4:1773</DocumentId>
		<DocumentId>dev4206:80f4cb:12279c825a4:1776</DocumentId>
	</DocumentList>
	<Prev_NotSuccess_Adv_Status>Primary document is null</Prev_NotSuccess_Adv_Status>
</ProcessData>

xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="html"/>
	<xsl:template match="/">
		<html>
			<xsl:apply-templates select="ProcessData"/>
		</html>
	</xsl:template>
	<xsl:template match="ProcessData">
		<table border="solid 3px">
			<tr>
				<th>DocumentList Nr.</th>
			</tr>
			<xsl:apply-templates select="//DocumentId"/>
			<tr>
				<td>
               <!-- here is the count command-->
					<xsl:value-of select="concat('Summe  : ',count(//DocumentId))"/>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="DocumentId">
		<tr><td><xsl:value-of select="position()"/></td>
			<td>
				<xsl:value-of select="."/>
			</td>
		</tr>
	</xsl:template>
</xsl:stylesheet>

then will be create a Html page

<html>
  <table border="solid 3px">
    <tr>
      <th>DocumentList Nr.</th>
    </tr>
    <tr>
      <td>1</td>
      <td>dev4206:80f4cb:12279c825a4:176f</td>
    </tr>
    <tr>
      <td>2</td>
      <td>dev4206:80f4cb:12279c825a4:1773</td>
    </tr>
    <tr>
      <td>3</td>
      <td>dev4206:80f4cb:12279c825a4:1776</td>
    </tr>
    <tr>
      <td>Summe  : 3</td>
    </tr>
  </table>
</html>

Am using mozilla firefox browser. Tried in IE also, but no result.
Can anyone please help me out?

What do you mean? How are you using your browser to get the count. Can you show us your stylesheet?

What do you mean? How are you using your browser to get the count. Can you show us your stylesheet?

Hi,
Am not using any stylesheet here. I'm working on Gentran Integration Suite and the xml file which I've given is the file generated from Gentran server. I want to get DocumentId count in developing one of the Business Process(BP), so I tried externally to find the count(Pls check below), but couldn't. To my surprise count(//DocumentId) worked well in the server. But I don't know why it's not working with the below code. Could please help me. Thanks in Advance...:)

// Sample HTML file
<code>
<html>
<body>
<script type="text/javascript">
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}
xml=loadXMLDoc("/home/miracle/Desktop/ProcessData.xml");
path = "count(//DocumentId)"

// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);

for (i=0;i<nodes.length;i++)
{
document.write(nodes.childNodes[0].nodeValue);
document.write("<br />");
}
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();

while (result)
{
document.write(result.childNodes[0].nodeValue);
document.write("<br />");
result=nodes.iterateNext();
}
}
</script>
</body>
</html>
</code>

// Here is XML file generated by Gentran server
<code>
<?xml version="1.0" encoding="UTF-8"?>

<ProcessData>

<SessionBeginTime>2009-07-15 09:01:37.687</SessionBeginTime>

<SessionToken>FTPClientAdapter_FTPClientAdapter_node1_12476736976871096:9472</SessionToken>

<Status>0</Status>

<ServerResponse>

<Code>250</Code>

<Text>250 CWD successful. "/Prav1" is current directory.</Text>

</ServerResponse>

<TranscriptDocumentId>dev4206:80f4cb:1227ba94d1e:5b70</TranscriptDocumentId>

<TranscriptDocument_1 SCIObjectID="dev4206:80f4cb:1227ba94d1e:5b73"/>

<TranscriptDocumentId>dev4206:80f4cb:1227ba94d1e:5b89</TranscriptDocumentId>

<TranscriptDocument_2 SCIObjectID="dev4206:80f4cb:1227ba94d1e:5b8c"/>

<TranscriptDocument_4 SCIObjectID="dev4206:80f4cb:1227ba94d1e:5be8"/>

<FSA_Document1.txt SCIObjectID="dev4206:80f4cb:1227ba94d1e:5be9"/>

<FSA_Document2.txt SCIObjectID="dev4206:80f4cb:1227ba94d1e:5bea"/>

<FSA_Document3.txt SCIObjectID="dev4206:80f4cb:1227ba94d1e:5beb"/>

<FSA_Document4.txt SCIObjectID="dev4206:80f4cb:1227ba94d1e:5bec"/>

<Status>0</Status>

<TranscriptDocumentId>dev4206:80f4cb:1227ba94d1e:5bde</TranscriptDocumentId>

<ServerResponse>

<Code>226</Code>

<Text>226 Transfer OK</Text>

</ServerResponse>

<DocumentList>

<DocumentId>dev4206:80f4cb:1227ba94d1e:5ba8</DocumentId>

<DocumentId>dev4206:80f4cb:1227ba94d1e:5bb5</DocumentId>

<DocumentId>dev4206:80f4cb:1227ba94d1e:5bb8</DocumentId>

<DocumentId>dev4206:80f4cb:1227ba94d1e:5bbb</DocumentId>

</DocumentList>

<count>1</count>

</ProcessData>
</code>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.