I've an XML document and I am creating another XML using XSL. I need to check some specific conditions and for that I want to use Javascript in my XSL. I tried it, however, couldn't get the desired result. As I could not change the XSL variables frequiently so i am trying to use Javascript.
XSL-
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:es="http://ucmservice"
version="1.0" xml开发者_如何学Pythonns="http://filenet.com/namespaces/wcm/apps/1.0" xmlns:java="http://xml.apache.org/xalan/java" xmlns:js="urn:custom-javascript" xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:totalSys="TotalSystem" extension-element-prefixes="totalSys">
<lxslt:component prefix="totalSys" functions="checkFirstProp">
<lxslt:script lang="javascript">
var firstPropVal = "";
var secondPropVal = "";
var completedFirstPropVal= new Array();
var completedSecondPropVal= new Array();
var firstDecisionFlag = 0;
function checkFirstProp(xmlValue)
{
firstDecisionFlag = 0;
if(firstPropVal.length == 0)
{
firstPropVal = xmlValue;
firstDecisionFlag = 1;
}
else
{
if(firstPropVal != xmlValue)
{
firstPropVal = xmlValue;
firstDecisionFlag = 2;
}
}
return firstDecisionFlag;
}
</lxslt:script>
</lxslt:component>
<xsl:template match="/">
<xsl:apply-templates select="XMLTag"/>
</xsl:template>
<xsl:template match="XMLTag">
<xsl:variable name="firstPropDecisionFlag">
<xsl:value-of select="totalSys:checkFirstProp(param)"/>
</xsl:variable>
<xsl:if test="$firstPropDecisionFlag=2">
{
task
}
</xsl:if>
</xsl:template>
bvk</xsl:stylesheet>
this gave me an error message-
[7/20/10 16:41:47:106 IST] 0000002e SystemErr R
org.apache.xalan.extensions.ObjectFactory$ConfigurationError
: Providerorg.apache.bsf.BSFManager
not found
Please advise, where am i going wrong?
Try wrapping the javascript code in a CDATA
section.
<script>
<![CDATA[
(function(){
//...
})();
]]>
</script>
The error says that you need the Apache Bean Scripting Framework in your classpath. You can get it here.
精彩评论