943,539 Members | Top Members by Rank

Ad:
Jul 14th, 2009
0

Illustrating count function

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
urs.karuna1218 is offline Offline
5 posts
since Jul 2009
Jul 14th, 2009
0

Re: Illustrating count function

count(//DocumentId)
Reputation Points: 16
Solved Threads: 21
Junior Poster
xml_looser is offline Offline
178 posts
since Apr 2009
Jul 15th, 2009
0

Re: Illustrating count function

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........
Reputation Points: 10
Solved Threads: 0
Newbie Poster
urs.karuna1218 is offline Offline
5 posts
since Jul 2009
Jul 15th, 2009
0

Re: Illustrating count function

I do not what is the Probelm

an Example

xml with xsl

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="process.xsl"?>
  3. <ProcessData>
  4. <SessionBeginTime>2009-07-14 13:24:28.218</SessionBeginTime>
  5. <ServerResponse>
  6. <Code>226</Code>
  7. <Text>226 Transfer OK</Text>
  8. </ServerResponse>
  9. <DocumentList>
  10. <DocumentId>dev4206:80f4cb:12279c825a4:176f</DocumentId>
  11. <DocumentId>dev4206:80f4cb:12279c825a4:1773</DocumentId>
  12. <DocumentId>dev4206:80f4cb:12279c825a4:1776</DocumentId>
  13. </DocumentList>
  14. <Prev_NotSuccess_Adv_Status>Primary document is null</Prev_NotSuccess_Adv_Status>
  15. </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

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <html>
  2. <table border="solid 3px">
  3. <tr>
  4. <th>DocumentList Nr.</th>
  5. </tr>
  6. <tr>
  7. <td>1</td>
  8. <td>dev4206:80f4cb:12279c825a4:176f</td>
  9. </tr>
  10. <tr>
  11. <td>2</td>
  12. <td>dev4206:80f4cb:12279c825a4:1773</td>
  13. </tr>
  14. <tr>
  15. <td>3</td>
  16. <td>dev4206:80f4cb:12279c825a4:1776</td>
  17. </tr>
  18. <tr>
  19. <td>Summe : 3</td>
  20. </tr>
  21. </table>
  22. </html>
Last edited by xml_looser; Jul 15th, 2009 at 12:13 pm.
Reputation Points: 16
Solved Threads: 21
Junior Poster
xml_looser is offline Offline
178 posts
since Apr 2009
Jul 20th, 2009
0

Re: Illustrating count function

Quote ...
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?
Reputation Points: 22
Solved Threads: 11
Junior Poster
fpmurphy is offline Offline
144 posts
since Oct 2008
Jul 20th, 2009
0

Re: Illustrating count function

Click to Expand / Collapse  Quote originally posted by fpmurphy ...
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[i].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>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
urs.karuna1218 is offline Offline
5 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: how to get all elemets using XPath
Next Thread in XML, XSLT and XPATH Forum Timeline: I'm way out of my depth and need desperate help.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC