我想在xpath表达式中使用xslt参数的值.具体来说,作为< xsl:if表达式中not()调用的一部分.
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- my_param contains a string '/foo/bar',passed in from ant --> <!-- the 'no' is just a default value --> <xsl:param name="my_param">no</xsl:param> <xsl:variable name="var_myparam" select="$my_param" /> <!-- ... --> <!-- this works --> <xsl:if test="not(/foo/bar)" /> <!-- expression returns boolean true --> <!-- ... --> </xsl:if> <!-- I can't figure out how to do this the right way --> <!-- None of these appear to work --> <xsl:if test="not($var_myparam)" /> <!-- expression returns boolean false --> <!-- ... --> </xsl:if> <xsl:if test="not({$var_myparam})" /> <!-- complains required attribute 'test' is missing --> <!-- ... --> </xsl:if> <xsl:if test="not({$myparam})" /> <!-- complains required attribute 'test' is missing --> <!-- ... --> </xsl:if> <xsl:if test="not($myparam)" /> <!-- expression returns boolean false --> <!-- ... --> </xsl:if> </xsl:transform>
我有点不清楚在xslt样式表中创建动态xpath表达式的正确语法是什么.对于参数,变量以及两者的扩展方式之间的差异,我也有点模糊.例如,有了参数,我知道有时我需要括号,有时我不需要.
<!-- when creating an element,it seems I need brackets --> <xsl:element name="{$my_param}" /> <!-- when selecting an element value for the output stream,no brackets are needed --> <xsl:value-of select="$my_param"/>
任何一般/特定的帮助将不胜感激.
查看
http://www.exslt.org/. 具体来看动态:评估模块.