Xml 在XSL中使用Javascript时出错
我有一个XML文档,正在使用XSL创建另一个XML。我需要检查一些特定的条件,为此我想在XSL中使用Javascript。我试过了,但是没有达到预期的效果。因为我不能频繁地更改XSL变量,所以我尝试使用Javascript XSL- 这给了我一个错误信息- [7/20/1016:41:47:106 IST]0000002e 系统错误 org.apache.xalan.extensions.ObjectFactory$ConfigurationError: 提供者org.apache.bsf.BSFManager 找不到Xml 在XSL中使用Javascript时出错,xml,xalan,Xml,Xalan,我有一个XML文档,正在使用XSL创建另一个XML。我需要检查一些特定的条件,为此我想在XSL中使用Javascript。我试过了,但是没有达到预期的效果。因为我不能频繁地更改XSL变量,所以我尝试使用Javascript XSL- 这给了我一个错误信息- [7/20/1016:41:47:106 IST]0000002e 系统错误 org.apache.xalan.extensions.ObjectFactory$ConfigurationError: 提供者org.apache.bsf.BS
请告知,我哪里出错了?尝试将javascript代码包装到CDATA部分
该错误表示在类路径中需要ApacheBean脚本框架。你可以得到它。我也试过了。。但是,只有当我必须将XML更改为html时,这才起作用。在目前的情况下,我正在尝试将我的xml转换为另一种所需的格式xml。。。因此,这些lxslt标记实际上允许您在样式表中的XML文档上执行javascript。很酷。看起来,除了纯xsl之外,您真的不需要任何东西来完成javascript的工作,但我对那些lxslt标记一无所知,所以我可能错了。检查一下skaffman的答案……我试图用纯xsl做同样的事情,但是做不到。在我的例子中,我需要一次又一次地更改变量值,而在xsl中,我必须在同一个位置声明和定义变量。谢谢Skaffman。。它需要3个jar文件,我添加了它们,然后就可以工作了。
<?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" xmlns="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>
<script>
<![CDATA[
(function(){
//...
})();
]]>
</script>