在XSL中使用Javascript时出错

时间:2010-07-20 12:56:46

标签: xml xalan

我有一个XML文档,我正在使用XSL创建另一个XML。我需要检查一些特定条件,为此我想在我的XSL中使用Javascript。然而,我尝试过,无法获得理想的结果。因为我无法频繁更改XSL变量所以我尝试使用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" 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> 

这给了我一条错误信息 -

  

[7/20/10 16:41:47:106 IST] 0000002e   SystemErr R   org.apache.xalan.extensions.ObjectFactory$ConfigurationError:   提供商org.apache.bsf.BSFManager   找不到

请告知我哪里出错?

2 个答案:

答案 0 :(得分:0)

尝试将javascript代码包装在CDATA部分。

<script>
<![CDATA[
(function(){
  //...
})();
]]>
</script>

答案 1 :(得分:0)

错误表明您需要在类路径中使用Apache Bean Scripting Framework。你可以得到它here

相关问题