Reputation: 437
In XSLT 2 style sheet
If simple boolean expression that has only 0, 1, and, or, (, ) tokens that is contained in string variable.
Than how to get the final value of expression. along with I need to use tokenize(), replace() function also.
Is here some xslt 2 processor that has support of exslt:evaluate() also on Ubuntu ? Saxon, Xalan, xsltproc I tried but Xalan, xsltproc do not support tokenize() and replace(). not sure about evaluate() also.
<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>
Here myfun:getexpr() return simple boolean expression.
or here some other approch to this boolean expression's final value.
Upvotes: 0
Views: 384
Reputation: 437
I tried 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) < 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>
Upvotes: 0
Reputation: 163625
Saxon has an extension function saxon:evaluate() which is similar to exslt:evaluate() but differs in detail; the main difference is that it doesn't allow direct access to variables declared in the stylesheet, but does allow parameter passing instead.
Upvotes: 0