Bug 31147

Summary: using Node variables with JSTL XML tags
Product: Taglibs Reporter: Flavio <flaviotordini>
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P3    
Version: 1.1.0   
Target Milestone: ---   
Hardware: Other   
OS: other   
Attachments: Patch for XPathUtil.java

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:

A solution proposal is in this message:

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?

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.