Using Javascript for counter...Stuck...need help!!!
Posted: Wed Oct 03, 2012 2:29 am
Here's my requirement. To Have a running counter in a for-loop and then when the for-loop completes display the total rows processed. Thought this would be the easiest to do, but I have spent more than 5 hours trying to figure this simple counter value displayed.
So result should say
1|xxx|1234
2|jhgh|4343
3|nhkj|4442
Total Rowcount: 3
I tried using position() function, but since i put it in for loop it display row number after each row. I tried to use it as a template variable calling another template, but that didnt work either. So finally thought of using Javascript and then call the counter function withn the javascript. But the script is erroringout. Here's the code snippet
xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:myExt="urn:com.schemas-microsoft-com:xslt">
<xsl:output method="html" version='4.0' encoding='UTF-8' indent='yes'/>
<msxsl:script language="javascript" implements-prefix="myExt">
<![CDATA[
var segmentCount = 0;
function AddSegments(addition)
{
segmentCount = segmentCount + addition;
return segmentCount;
}
function GetSegmentsCount()
{
return segmentCount;
}
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:for-each
<xsl:with-param name="counter" select="position()"/>
<xsl:variable name="headerSegmentCount" select="myExt:AddSegments(@counter)" />
</xsl:for-each
<xsl>Total Row Count:</xsl>|<xsl:variable name="totalSegmentCount" select="myExt:GetSegmentsCount()" />
When I run this I get the following message.
Engine name: Saxon6.5.5
Severity: error
Description: The URI urn:com.schemas-microsoft-com:xslt does not identify an external Java class
Start location: 83:0
Help please!
So result should say
1|xxx|1234
2|jhgh|4343
3|nhkj|4442
Total Rowcount: 3
I tried using position() function, but since i put it in for loop it display row number after each row. I tried to use it as a template variable calling another template, but that didnt work either. So finally thought of using Javascript and then call the counter function withn the javascript. But the script is erroringout. Here's the code snippet
xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:myExt="urn:com.schemas-microsoft-com:xslt">
<xsl:output method="html" version='4.0' encoding='UTF-8' indent='yes'/>
<msxsl:script language="javascript" implements-prefix="myExt">
<![CDATA[
var segmentCount = 0;
function AddSegments(addition)
{
segmentCount = segmentCount + addition;
return segmentCount;
}
function GetSegmentsCount()
{
return segmentCount;
}
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:for-each
<xsl:with-param name="counter" select="position()"/>
<xsl:variable name="headerSegmentCount" select="myExt:AddSegments(@counter)" />
</xsl:for-each
<xsl>Total Row Count:</xsl>|<xsl:variable name="totalSegmentCount" select="myExt:GetSegmentsCount()" />
When I run this I get the following message.
Engine name: Saxon6.5.5
Severity: error
Description: The URI urn:com.schemas-microsoft-com:xslt does not identify an external Java class
Start location: 83:0
Help please!