jstl xml variables for select attribute

2019-08-10 09:43发布

I'm using jstl xml to get specified values from an XML

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>

The node is not selected according to the role-id provided. it works if I use only the right hand side as a variable.

What is the issue here?

标签: xml jsp jstl
1条回答
小情绪 Triste *
2楼-- · 2019-08-10 10:10

There are a few problems here:

  • 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 variable
  • c:set variables are not in the XML scope, unlike x:parse variables
  • userRoleSelector is a JSP variable

To test the role-id properly, try this instead:

[@role-id='test']

To test the JSP variable, try this instead:

[@role-id=$sessionScope:userRoleSelector]

References

查看更多
登录 后发表回答