Reputation: 149
In a JSP I have the user language code (en, de, es, etc) stored in a variable. This value comes from the database.
In the other hand I have a XML file with all the values of the different languages, something like this:
<?xml version="1.0" encoding="UTF-8"?>
<language>
<en enable="false" />
<de enable="false" />
</emergency>
I am trying to use that variable in a XSTL select but nothing that I have tried works (and I tried a lot of crazy things):
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<c:set var="USER_LANGUAGE" value="en" />
<c:import url="/languageData.xml" var="language" />
<x:parse xml="${language}" var="language" />
// work
// <x:if select="$language/en[@enable = 'true']">
// don't work :(
<x:if select="$language/${USER_LANGUAGE}[@enable = 'true']">
// magic
</x:if>
Looks like I'm missing something, any help will be very welcome.
Thanks!
Upvotes: 0
Views: 444
Reputation: 149
Finally I found a solution!:
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<c:set var="USER_LANGUAGE" value="en" />
<c:import url="/languageData.xml" var="language" />
<x:parse xml="${language}" var="language" />
<x:if select="$language/*[name()=$pageScope:USER_LANGUAGE][@enable = 'true']">
// magic
</x:if>
Hope it helps!
Upvotes: 1