【问题标题】:xslt 2 processor that has support of exslt:evaluate()支持 exslt:evaluate() 的 xslt 2 处理器
【发布时间】:2011-04-30 18:50:54
【问题描述】:

在 XSLT 2 样式表中

如果简单的布尔表达式只有 0, 1, and, or, (, ) 记号 包含在字符串变量中。

比如何得到表达式的最终值。 同时我还需要使用 tokenize()、replace() 函数。

这里有一些 xslt 2 处理器在 Ubuntu 上也支持 exslt:evaluate() 吗? Saxon、Xalan、xsltproc 我试过,但 Xalan、xsltproc 不支持 tokenize() 和 replace()。 也不确定 evaluate()。

<xsl:template name="test">
  <xsl:variable name="nexpression" select="myfun:getexpr()"/>
  <!-- return boolean exp   like "0 or (1 and 1) or 1" -->
  <xsl:value-of select="exslt:evaluate($nexpression)"/>
</xsl:template>

这里 myfun:getexpr() 返回简单的布尔表达式。

或者这里其他方法到这个布尔表达式的最终值。

【问题讨论】:

    标签: xml xslt exslt


    【解决方案1】:

    Saxon 有一个扩展函数 saxon:evaluate(),它与 ​​exslt:evaluate() 类似,但在细节上有所不同;主要区别在于它不允许直接访问样式表中声明的变量,而是允许传递参数。

    【讨论】:

    • saxon home edition saxon9he 和 saxonb8-9.jar 不支持 saxon:evaluation 目前我有。谢谢
    【解决方案2】:

    我试过 myfn:getexpval()

    <xsl:stylesheet version="2.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:exslt="http://exslt.org/common"
                    xmlns:myfn="http://whatever"
                    xmlns:functx="http://www.functx.com">
    
      <xsl:function name="myfn:getexpval">
        <xsl:param name="exp"/>
        <xsl:value-of select="if (matches($exp, $openp) != ()) then
                                myfn:clget-simple-expval(concat(substring-before($exp, $openp),
                                                                myfn:clfoundopen(substring-after($exp, $openp))))
                              else myfn:clget-simple-expval($exp)
                              "/>
    
      </xsl:function>
    
      <xsl:function name="myfn:clfoundopen">
        <xsl:param name="openexp"/>
        <xsl:value-of select="if (matches($openexp, $openp) != () and
                                  functx:index-of-string-first($openexp, $openp) &lt; functx:index-of-string-first($openexp, $closep)
                                 ) then
                                myfn:clget-simple-expval(concat(substring-before($openexp, $openp),
                                                                myfn:clfoundopen(substring-after($openexp, $openp))))
                              else
                                myfn:clget-simple-expval(concat(substring-before($openexp, $closep),
                                                                myfn:clfoundopen(substring-after($openexp, $closep))))
                              "/>
      </xsl:function>
      <xsl:function name="myfn:clget-simple-expval">
        <xsl:param name="exp"/>
        <xsl:variable name="ztokens" select="tokenize($exp, 'or')"/>
        <xsl:variable name="forret">
          <xsl:value-of select="some $i in $ztokens satisfies
                                myfn:cland($i) = true()"/>
        </xsl:variable>
    
        <xsl:value-of select="if ($forret = true())
                              then
                              1
                              else
                              0"/>
    
      </xsl:function>
    
      <xsl:function name="myfn:cland">
        <xsl:param name="exp"/>
        <xsl:variable name="ztokens" select="tokenize($exp, 'and')"/>
        <xsl:variable name="forret">
          <xsl:value-of select="every $i in $ztokens satisfies
                                replace($i, ' ', '') eq '1'"/>
        </xsl:variable>
        <xsl:value-of select="$forret"/>
      </xsl:function>
    
      <xsl:value-of select="myfn:getexpval('0 or ( 1 and 1 )')"/>
    
    </xsl:stylesheet>
    

    【讨论】:

      猜你喜欢
      • 2010-10-05
      • 2014-05-24
      • 2020-08-06
      • 1970-01-01
      • 2018-08-15
      • 2011-01-25
      • 2012-03-15
      • 2010-12-26
      • 2015-07-17
      相关资源
      最近更新 更多