Hi,
I have a feeling this must be a common problem but I'm afraid I can't
find the answer...
I am trying to use the JSTL x tags in v1.1.2 of the 'standard' tag
library. Something like this:
<c:import url="WorkItem.xml" var="url" />
<x:parse xml="${url}" var="doc" />
<x:out select="$doc/ap:ActionResult" />
The problem is the namespace in my XPath query and it results in the
error:
com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
Prefix must resolve to a namespace: ap
Fair enough. But how can I tell the x:out tag about the namespace?
In Java I would write a NamespaceContext implementation and supply
that to the XPath engine. Something like this:
NamespaceContext ctx = new NamespaceContext() {
public String getNamespaceURI(String prefix) {
String uri;
if (prefix.equals("ap"))
uri = "http://example.com/ap";
else
uri = null;
return uri;
}
// Dummy implementation - not used!
public Iterator getPrefixes(String val) {
return null;
}
// Dummy implemenation - not used!
public String getPrefix(String uri) {
return null;
}
};
// Now the XPath expression
String xpathStr = "/ap:ActionResult";
XPathFactory xpathFact = XPathFactory.newInstance();
XPath xpath = xpathFact.newXPath();
xpath.setNamespaceContext(ctx);
String result = xpath.evaluate(xpathStr, doc);
In JSTL it seems there is no equivalent? Is there any 'under the
radar' way to supply the namespace context to the tag?
Seems a real shame to have to write a new taglib just to support this...
thanks for your suggestions,
Tim
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscr...@jakarta.apache.org
For additional commands, e-mail: taglibs-user-h...@jakarta.apache.org