Using Javascript for counter...Stuck...need help!!!
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 8
- Joined: Tue Oct 02, 2012 4:53 am
Using Javascript for counter...Stuck...need help!!!
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!
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Using Javascript for counter...Stuck...need help!!!
I wouldn't use JavaScript in a stylesheet just for a counter, it's overkill. Try to learn a bit of XSLT and XPath and it will make things much easier.
As to why it's not working, you're trying to use the 'msxsl' XSLT extension with a non-Microsoft XML transformer. Saxon doesn't support 'msxsl', you'll have to use either the MSXML or the .NET transformers.
Search the forums when you encounter problems like these, they are rather common and usually have been discussed and resolved.
Regards,
Adrian
As to why it's not working, you're trying to use the 'msxsl' XSLT extension with a non-Microsoft XML transformer. Saxon doesn't support 'msxsl', you'll have to use either the MSXML or the .NET transformers.
Search the forums when you encounter problems like these, they are rather common and usually have been discussed and resolved.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service