Illustrating count function

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 5
Reputation: urs.karuna1218 is an unknown quantity at this point 
Solved Threads: 0
urs.karuna1218 urs.karuna1218 is offline Offline
Newbie Poster

Illustrating count function

 
0
  #1
Jul 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 44
Reputation: xml_looser is an unknown quantity at this point 
Solved Threads: 2
xml_looser xml_looser is offline Offline
Light Poster

Re: Illustrating count function

 
0
  #2
Jul 14th, 2009
count(//DocumentId)
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 5
Reputation: urs.karuna1218 is an unknown quantity at this point 
Solved Threads: 0
urs.karuna1218 urs.karuna1218 is offline Offline
Newbie Poster

Re: Illustrating count function

 
0
  #3
Jul 15th, 2009
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........
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 44
Reputation: xml_looser is an unknown quantity at this point 
Solved Threads: 2
xml_looser xml_looser is offline Offline
Light Poster

Re: Illustrating count function

 
0
  #4
Jul 15th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 95
Reputation: fpmurphy is an unknown quantity at this point 
Solved Threads: 5
fpmurphy fpmurphy is offline Offline
Junior Poster in Training

Re: Illustrating count function

 
0
  #5
Jul 20th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 5
Reputation: urs.karuna1218 is an unknown quantity at this point 
Solved Threads: 0
urs.karuna1218 urs.karuna1218 is offline Offline
Newbie Poster

Re: Illustrating count function

 
0
  #6
Jul 20th, 2009
Originally Posted by fpmurphy View Post
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>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC