Getting x:set var
The following code displays [[rplyCode: null]]. x:set var = Code select = '.' scope = page / %= pageContext.getAttribute(Code) % Whats the proper way to access the Code variable value?
x:set var
All, For the life of me, I cannot figure out why the following examples produce different results. Many thanks in advance if anyone can help. I'm importing an XML doc with the following: x:parse var=reports c:import url=reports.xml/ /x:parse If I use x:out select=$reports//report[@shortname='biweekly']/id / I get the expected result, 157. However, if I use x:set var=reportID select=$reports//report[@shortname='biweekly']/id / c:out value=${reportID} / I get, [[id: null]]. The xPath syntax is obviously correct, as I'm getting the expected result with the x:out tag. So, any idea what I'm doing wrong when I try to expose the same result in the variable reportID? Thanks again, Buck Bell -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: x:set var
On Mon, 13 Jan 2003 [EMAIL PROTECTED] wrote: All, For the life of me, I cannot figure out why the following examples produce different results. Many thanks in advance if anyone can help. I'm importing an XML doc with the following: x:parse var=reports c:import url=reports.xml/ /x:parse If I use x:out select=$reports//report[@shortname='biweekly']/id / I get the expected result, 157. However, if I use x:set var=reportID select=$reports//report[@shortname='biweekly']/id / c:out value=${reportID} / I get, [[id: null]]. The xPath syntax is obviously correct, as I'm getting the expected result with the x:out tag. So, any idea what I'm doing wrong when I try to expose the same result in the variable reportID? The x:out tag uses the string-value of the element you have selected. x:set stores the object representing that node itself, and then c:out prints the toString() value of that node -- which, per the DOM API, isn't the same thing as what XPath means by string-value. To store the value you expect instead of outputting it immediately, you should use a pattern like c:set x:out /c:set instead of x:set. Alternatively, you can wrap the XPath expression in the string() function and continue to use x:set. Hope that helps, -- Shawn Bayern JSTL in Action http://www.manning.com/bayern -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: x:set var
Shawn, Thanks for both the explanation and the fix. This is definitely one of those du moments, after reading your explanation. Works perfectly now. Best regards, Buck Bell -- Original Message -- Reply-To: Tag Libraries Users List [EMAIL PROTECTED] Date: Mon, 13 Jan 2003 13:19:57 -0500 (EST) From: Shawn Bayern [EMAIL PROTECTED] To: Tag Libraries Users List [EMAIL PROTECTED] Subject: Re: x:set var On Mon, 13 Jan 2003 [EMAIL PROTECTED] wrote: All, For the life of me, I cannot figure out why the following examples produce different results. Many thanks in advance if anyone can help. I'm importing an XML doc with the following: x:parse var=reports c:import url=reports.xml/ /x:parse If I use x:out select=$reports//report[@shortname='biweekly']/id / I get the expected result, 157. However, if I use x:set var=reportID select=$reports//report[@shortname='biweekly']/id / c:out value=${reportID} / I get, [[id: null]]. The xPath syntax is obviously correct, as I'm getting the expected result with the x:out tag. So, any idea what I'm doing wrong when I try to expose the same result in the variable reportID? The x:out tag uses the string-value of the element you have selected. x:set stores the object representing that node itself, and then c:out prints the toString() value of that node -- which, per the DOM API, isn't the same thing as what XPath means by string-value. To store the value you expect instead of outputting it immediately, you should use a pattern like c:set x:out /c:set instead of x:set. Alternatively, you can wrap the XPath expression in the string() function and continue to use x:set. Hope that helps, -- Shawn Bayern JSTL in Action http://www.manning.com/bayern -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]