首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xslt 2处理器,支持exslt:exslt()

xslt 2处理器,支持exslt:exslt()
EN

Stack Overflow用户
提问于 2011-04-30 18:50:54
回答 2查看 375关注 0票数 0

在XSLT 2样式表中

如果只包含在字符串变量中的0、1和或( )标记的简单布尔表达式。

而不是如何得到表达式的最终值。在使用tokenize()的同时,也需要替换()函数。

这里有一些xslt 2处理器支持exslt:exslt()在Ubuntu上吗?Saxon、Xalan、xsltproc我试过了,但是Xalan、xsltproc不支持tokenize()和替换()。也不确定是否要评估()。

代码语言:javascript
复制
<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>

这里我的意思是:getexpr()返回简单的布尔表达式。

或者在这里,对这个布尔表达式的最终值进行一些其他的处理,

EN

回答 2

Stack Overflow用户

发布于 2011-04-30 22:07:21

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

票数 0
EN

Stack Overflow用户

发布于 2011-05-01 18:03:11

我尝试了myfn:getexpval()

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5843925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档