Bug 31147 - using Node variables with JSTL XML tags
Summary: using Node variables with JSTL XML tags
Status: RESOLVED FIXED
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: 1.1.0
Hardware: Other other
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-09 16:18 UTC by Flavio
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments
Patch for XPathUtil.java (2.12 KB, patch)
2004-09-10 02:49 UTC, Kris Schneider
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Flavio 2004-09-09 16:18:31 UTC
hi all,
I have a org.w3c.dom.Node variable and I'm trying to use the JSTL with it.
Something like:

<x:out select="$node/@name"/>

The odd thing is that the XPath expression is evaluated relative to the document
root, not to the specified node. The following works:

<x:out select="$node/full/path/to/node/@name"/>

I'm filing this bug after a discussion on the taglibs-user mailing list:
http://www.mail-archive.com/taglibs-user@jakarta.apache.org/msg07667.html

A solution proposal is in this message:
http://www.mail-archive.com/taglibs-user@jakarta.apache.org/msg07682.html

regards,
flavio
Comment 1 Kris Schneider 2004-09-09 17:35:20 UTC
I've got what appears to be a working fix, but I'll want to post a patch for
review as opposed to blindly committing it. I'm just not that familiar with the
nuances of XPathUtil. Patch to follow, hopefully tonight.
Comment 2 Kris Schneider 2004-09-10 02:49:48 UTC
Created attachment 12691 [details]
Patch for XPathUtil.java
Comment 3 Flavio 2004-09-10 09:00:37 UTC
Maybe there is another (faster) way to achieve the same result. instead of
creating a new Document and prepend "/*" to the original XPath, we may simply
remove the starting slash from the XPath.

xpath = xpath.substring( xpath.indexOf("/"));
(XPathUtils 648)

would become:
xpath = xpath.substring( xpath.indexOf("/") + 1);

Then evaluate the XPath with the original Node as its context.
I don't know if this may have side-effects, but I think this is the way to go.
What do you think?

flavio
Comment 4 Justyna Horwat 2004-09-15 20:26:22 UTC
I tested Flavio's fix and found that it did not work in all cases. Tested and verified Kris Schneider's fix 
and committed it to the JSTL 1.1.x workspace.