| | |
Illustrating count function
Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 5
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Apr 2009
Posts: 44
Reputation:
Solved Threads: 2
I do not what is the Probelm
an Example
xml with xsl
xsl
then will be create a Html page
an Example
xml with xsl
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<?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
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<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>
Last edited by xml_looser; Jul 15th, 2009 at 12:13 pm.
•
•
Join Date: Jul 2009
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
What do you mean? How are you using your browser to get the count. Can you show us your stylesheet?
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>
![]() |
Similar Threads
- Using the COUNT function with a subquery in SQL (MySQL)
- count function (PHP)
- Query of Query - Using Count (ColdFusion)
- help with creating and calling a function (C++)
- MySQL count(*) (C#)
- I Need Help Writing A Word Count Program In My Python (Python)
- Need help on FileWrite function. (C++)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: how to get all elemets using XPath
- Next Thread: I'm way out of my depth and need desperate help.
| Thread Tools | Search this Thread |
api blogger blogging code delete development dynamiccreationofnvariablesinxslt error firstthreecharacterofastringrequired flipbook gdata google html include java link linspire linux microsoft news node openoffice overwrite precedence programming rss standards swf template transform variable w3c web xml xmlnotloading xmlonserver xsl xslt





