commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [jelly] XPath name() function broken in CVS ?
Date Wed, 13 Nov 2002 13:13:48 GMT
Hi Matthew

BTW in future could you prefix your mails to commons-dev or commons-user
with [jelly]? It just helps folks figure out which bit of the commons
project you're talking about. (We should document this fact on the Jelly
site).

From: "J. Matthew Pryor" <matthew_pryor@versata.com>
> Hi
>
> This worked fine with beta-7
>
> <x:copyOf trim="false" select="$feature/feature/*[name() !=
> 'requires']"/>
>
> But now with beta-8 CVS build (as of 10 minutes ago) I get the
> following:
>
> update-version:
>
> [ERROR] BUILD FAILED
> [ERROR] Function :name
> Total time:  2 seconds
>
> The XPath expression is OK isn't it?
>
> Did I do something incorrectly?

Your XPath expression is totally fine. Though a quick piece of XPath advice,
try to use local-name() instead as name() might include a namespace prefix.
Having a dependency on the namespace prefixes used in an XML document is
considered bad form; only the local name and the namespace URI should count
really.

The short answer to this problem is...

The reason for the failure is I broke it by accident recently when adding
some new namespace aware XPath features to Jelly - many appologies. I've
created a JellyUnit test case to demonstrate the bug

http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/src/test/org/apa
che/commons/jelly/xml/suite.jelly?rev=HEAD

and the bug is now fixed in CVS. There's a new Jelly snapshot build
containing this fix, so rebuild Maven and you should be OK.


Now here's the longer explanation of what went wrong and how its been fixed
(you can stop reading now if you like)...

I recently added support for namespaces inside XPath expressions, so that
you can use any namespace prefix in scope inside an XPath expression. e.g.

<whatever xmlns:x="jelly:xml" xmlns:my="someNamespaceURI">
..
    <x:parse var="doc">
        <my:foo>
            ...
            <my:bar/>
            ...
        </my:foo>
    </x:parse>
    ...
    <x:forEach select="$doc/my:foo/my:bar">
        ...
</whatever>

However the recent changes to support the above introduced a bug whereby the
default namespace (the namespace with no prefix defined via the xmlns="..."
XML attribute) was being passed from the Jelly document into the
NamespaceContext used to evaluate the Jaxen XPath expressions. This is a
bug. The NamespaceContext should never map an empty prefix to a namespace
URI other than "". If this does happen, the XPath functions (like name())
disappear as they are registered via the "" namespace URI.

I suspect the Jelly document you were using had xmlns="..." defined which is
why the XPath expression was failing. I've now fixed this issue by
explicitly ignoring the default namespace when constructing a Jaxen
NamespaceContext.

James
-------
http://radio.weblogs.com/0112098/

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message