tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Bayern <bay...@essentially.net>
Subject Re: x:set var
Date Mon, 13 Jan 2003 18:19:57 GMT
On Mon, 13 Jan 2003 bbell@brakus.com 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:taglibs-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-user-help@jakarta.apache.org>


Mime
View raw message