是否可以在 xslt 样式表中使用动态 xPath 表达式? [英] Is it possible to use a Dynamic xPath expression in a xslt style sheet?

查看:22
本文介绍了是否可以在 xslt 样式表中使用动态 xPath 表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 xpath 表达式中使用 xslt 参数的值.具体来说,作为 <xsl:if 表达式中 not() 调用的一部分.

I'd like to use the value of an xslt parameter in an xpath expression. Specifically, as part of a not() call in an <xsl:if expression.

<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 表达式的正确语法是什么.我对参数、变量以及两者的扩展如何工作之间的区别也有点模糊.比如带参数,我知道有时候需要括号,有时候不需要.

I'm a little unclear on what the correct syntax is for creating a dynamic xpath expression in an xslt style sheet. I'm also a little fuzzy on the difference between a paramater, a variable, and how expanstion of both works. For example, with parameters, I know that sometimes I need the brackets, and sometimes I don't.

<!-- 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"/>

任何一般/特定的帮助将不胜感激.

Any general/specific help would be greatly appreciated.

推荐答案

查看 http://www.exslt.org/.具体看 dynamic:evaluate 模块.

Check out http://www.exslt.org/. Specifically look at the dynamic:evaluate module.

这篇关于是否可以在 xslt 样式表中使用动态 xPath 表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆