选择属性的jstl xml变量 [英] jstl xml variables for select attribute
本文介绍了选择属性的jstl xml变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jstl xml从XML获取指定的值
I'm using jstl xml to get specified values from an XML
在这里,我使用"userRoleSelector"作为变量来选择节点.变量设置为
Here I'm using a "userRoleSelector" as a variable to select the node. The variable is set as,
<c:set var="userRoleSelector" value="role-id='test'" scope='session'/>
我使用变量的标记如下,
The tag where I use the variable is as follows,
<x:if select="$parsedRoleXML//roles/role[$userRoleSelector]/features/feature[text()='viewEvents']">
//html code
</x:if>
未根据提供的角色ID选择节点.如果我仅将右侧用作变量,则此方法有效.
The node is not selected according to the role-id provided. it works if I use only the right hand side as a variable.
这是什么问题?
推荐答案
这里有一些问题:
- XPath谓词语法
[$userRoleSelector]
没有进行比较 - XPath谓词语法正在搜索索引,而不是属性值
-
userRoleSelector
不是XPath变量
与 -
c:set
变量不在XML范围内 -
userRoleSelector
是一个JSP变量
x:parse
变量不同,- The XPath predicate syntax
[$userRoleSelector]
is not doing a comparison - The XPath predicate syntax is searching for an index, not an attribute value
userRoleSelector
is not an XPath variablec:set
variables are not in the XML scope, unlikex:parse
variablesuserRoleSelector
is a JSP variable
要正确测试角色ID,请尝试以下操作:
To test the role-id properly, try this instead:
[@role-id='test']
要测试JSP变量,请尝试以下方法:
To test the JSP variable, try this instead:
[@role-id=$sessionScope:userRoleSelector]
参考
- XPath: Variable Reference
- JSP - XML Data
- JSR-52: jstl-1_0-fr-spec.pdf
这篇关于选择属性的jstl xml变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文