You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Bill Burton <bi...@progress.com> on 2002/03/06 01:21:22 UTC

[DVSL] #match and unions fail?

Hello,

I'm attempting to use the #match directive with unions to match one node
or another:
    #match( "aaa | bbb" )
What I'm finding is it matches "aaa" nodes but not "bbb" nodes.

The real easy way to reproduce this is to modify
examples/simple/docs/example1.dvsl changing:
    #match("document")
to
    #match("aaa | document")
it will then fail to match on "document" and not output the <html>
section.  However, changing it to:
    #match("document | aaa")
does work.

I'm assuming this is really a dom4j issue so I upgraded to version 1.2 but
this hasn't helped.  I'm attempting to reproduce this using the dom4j
API's.  In the meantime, I'm open to suggestions.

-Bill

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [DVSL] #match and unions fail?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 3/6/02 7:55 PM, "Bill Burton" <bi...@progress.com> wrote:

> Hello,
> 
> Just for the record, if anyone runs into this issue, there's a bug in
> jaxen utilized by dom4j-1.1.1 included with DVSL 0.42 and with the current
> dom4j-1.2.  The fix is to patch org.jaxen.pattern.UnionPattern as follows:
> 
> --- org/jaxen/pattern/UnionPattern.java.orig    Wed Aug  8 17:29:49 2001
> +++ org/jaxen/pattern/UnionPattern.java Wed Mar  6 01:39:51 2002
> @@ -91,7 +91,7 @@
>    public Pattern simplify()
>    {
>        this.lhs = lhs.simplify();
> -        this.rhs = lhs.simplify();
> +        this.rhs = rhs.simplify();
>        init();
>        return this;
>    }
> 
> Thanks Bob for the pointer to jaxen.

There was another bug that James fixed - so I will have a fixed dom4j jar in
CVS later tonight if consciousness persists...

:)

> 
> -Bill
> 
> Bill Burton wrote:
>> 
>> Hello,
>> 
>> I'm attempting to use the #match directive with unions to match one node
>> or another:
>>     #match( "aaa | bbb" )
>> What I'm finding is it matches "aaa" nodes but not "bbb" nodes.
>> 
>> The real easy way to reproduce this is to modify
>> examples/simple/docs/example1.dvsl changing:
>>     #match("document")
>> to
>>     #match("aaa | document")
>> it will then fail to match on "document" and not output the <html>
>> section.  However, changing it to:
>>     #match("document | aaa")
>> does work.
>> 
>> I'm assuming this is really a dom4j issue so I upgraded to version 1.2 but
>> this hasn't helped.  I'm attempting to reproduce this using the dom4j
>> API's.  In the meantime, I'm open to suggestions.
>> 
>> -Bill
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
The bytecodes are language independent. - Sam Ruby  


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [DVSL] #match and unions fail?

Posted by Bill Burton <bi...@progress.com>.
Hello,

Just for the record, if anyone runs into this issue, there's a bug in
jaxen utilized by dom4j-1.1.1 included with DVSL 0.42 and with the current
dom4j-1.2.  The fix is to patch org.jaxen.pattern.UnionPattern as follows:

--- org/jaxen/pattern/UnionPattern.java.orig    Wed Aug  8 17:29:49 2001
+++ org/jaxen/pattern/UnionPattern.java Wed Mar  6 01:39:51 2002
@@ -91,7 +91,7 @@
     public Pattern simplify()
     {
         this.lhs = lhs.simplify();
-        this.rhs = lhs.simplify();
+        this.rhs = rhs.simplify();
         init();
         return this;
     }

Thanks Bob for the pointer to jaxen.

-Bill

Bill Burton wrote:
> 
> Hello,
> 
> I'm attempting to use the #match directive with unions to match one node
> or another:
>     #match( "aaa | bbb" )
> What I'm finding is it matches "aaa" nodes but not "bbb" nodes.
> 
> The real easy way to reproduce this is to modify
> examples/simple/docs/example1.dvsl changing:
>     #match("document")
> to
>     #match("aaa | document")
> it will then fail to match on "document" and not output the <html>
> section.  However, changing it to:
>     #match("document | aaa")
> does work.
> 
> I'm assuming this is really a dom4j issue so I upgraded to version 1.2 but
> this hasn't helped.  I'm attempting to reproduce this using the dom4j
> API's.  In the meantime, I'm open to suggestions.
> 
> -Bill

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [DVSL] #match and unions fail?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 3/5/02 8:57 PM, "Bill Burton" <bi...@progress.com> wrote:

> Hello,
> 
> See below ...
> 
> bob mcwhirter wrote:
>> 
>>> I'm attempting to use the #match directive with unions to match one node
>>> or another:
>>>     #match( "aaa | bbb" )
>>> What I'm finding is it matches "aaa" nodes but not "bbb" nodes.
>>> 
>>> The real easy way to reproduce this is to modify
>>> examples/simple/docs/example1.dvsl changing:
>>>     #match("document")
>>> to
>>>     #match("aaa | document")
>>> it will then fail to match on "document" and not output the <html>
>>> section.  However, changing it to:
>>>     #match("document | aaa")
>>> does work.
>>> 
>>> I'm assuming this is really a dom4j issue so I upgraded to version 1.2 but
>>> this hasn't helped.  I'm attempting to reproduce this using the dom4j
>>> API's.  In the meantime, I'm open to suggestions.
>> 
>> dom4j uses Jaxen (http://jaxen.org/) under the covers for XPath stuff,
>> so if you want to boil things down to original sources, I suggest...
>> 
>> 1) Try a Document.selectNodes(...) through the dom4j API.
>> 
>>         If that fails...
>> 
>> 2) Try XPath.selectNodes( doc ) through the Jaxen API.
>> 
>> At one point, we didn't have the union operator working right, but
>> I think it's been fixed for a while, and dom4j 1.2 should have
>> integrated the latest jaxen sources, I think.
> 
> I wrote a little program that does something like the above:
>   XPath xpathSelector = DocumentHelper.createXPath(xpath);
>   List results = xpathSelector.selectNodes(doc);
> 
> The above works fine.  But it doesn't matter because DVSL isn't doing it
> that way.  The #match directive ultimately calls
> .dvsl.TemplateHandler.registerMatch with:
>   Pattern pattern = DocumentHelper.createPattern( xpath );
>   Rule rule = new Rule( pattern );
> which are saved in a HashMap for use when rendering the template.  Then in
> the render method of the same class, it's passed a dom4j Node and tests it
> with:
>   if( xpathrule.matches( dom4jnode ) )
> 
> Using the following, I was able to reproduce the problem:
>   Pattern pattern = DocumentHelper.createPattern( "aaa | bbb" )
>   Rule rule = new Rule( pattern );
>   Element root = doc.getRootElement();
>   System.out.println("root element: " + root.getName());
>   if (rule.matches(root))
>       System.out.println("match found!");
> 
> This succeeds for an <aaa> element but fails for a <bbb> element.  I'll
> take this over to the dom4j-dev list ...

I've got another problem with using the Rule() - it doesn't seem to match
for nodes that were found using the identical Xpath...  I've sent a note to
james, and I'll join you over on the dom4j list...

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
Java : the speed of Smalltalk with the simple elegance of C++... 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [DVSL] #match and unions fail?

Posted by Bill Burton <bi...@progress.com>.
Hello,

See below ...

bob mcwhirter wrote:
> 
> > I'm attempting to use the #match directive with unions to match one node
> > or another:
> >     #match( "aaa | bbb" )
> > What I'm finding is it matches "aaa" nodes but not "bbb" nodes.
> >
> > The real easy way to reproduce this is to modify
> > examples/simple/docs/example1.dvsl changing:
> >     #match("document")
> > to
> >     #match("aaa | document")
> > it will then fail to match on "document" and not output the <html>
> > section.  However, changing it to:
> >     #match("document | aaa")
> > does work.
> >
> > I'm assuming this is really a dom4j issue so I upgraded to version 1.2 but
> > this hasn't helped.  I'm attempting to reproduce this using the dom4j
> > API's.  In the meantime, I'm open to suggestions.
> 
> dom4j uses Jaxen (http://jaxen.org/) under the covers for XPath stuff,
> so if you want to boil things down to original sources, I suggest...
> 
> 1) Try a Document.selectNodes(...) through the dom4j API.
> 
>         If that fails...
> 
> 2) Try XPath.selectNodes( doc ) through the Jaxen API.
> 
> At one point, we didn't have the union operator working right, but
> I think it's been fixed for a while, and dom4j 1.2 should have
> integrated the latest jaxen sources, I think.

I wrote a little program that does something like the above:
    XPath xpathSelector = DocumentHelper.createXPath(xpath);
    List results = xpathSelector.selectNodes(doc);

The above works fine.  But it doesn't matter because DVSL isn't doing it
that way.  The #match directive ultimately calls
.dvsl.TemplateHandler.registerMatch with:
    Pattern pattern = DocumentHelper.createPattern( xpath );
    Rule rule = new Rule( pattern );
which are saved in a HashMap for use when rendering the template.  Then in
the render method of the same class, it's passed a dom4j Node and tests it
with:
    if( xpathrule.matches( dom4jnode ) )

Using the following, I was able to reproduce the problem:
    Pattern pattern = DocumentHelper.createPattern( "aaa | bbb" )
    Rule rule = new Rule( pattern );
    Element root = doc.getRootElement();
    System.out.println("root element: " + root.getName());
    if (rule.matches(root))
        System.out.println("match found!");

This succeeds for an <aaa> element but fails for a <bbb> element.  I'll
take this over to the dom4j-dev list ...

Thanks,
-Bill

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [DVSL] #match and unions fail?

Posted by bob mcwhirter <bo...@werken.com>.
> I'm attempting to use the #match directive with unions to match one node
> or another:
>     #match( "aaa | bbb" )
> What I'm finding is it matches "aaa" nodes but not "bbb" nodes.
> 
> The real easy way to reproduce this is to modify
> examples/simple/docs/example1.dvsl changing:
>     #match("document")
> to
>     #match("aaa | document")
> it will then fail to match on "document" and not output the <html>
> section.  However, changing it to:
>     #match("document | aaa")
> does work.
> 
> I'm assuming this is really a dom4j issue so I upgraded to version 1.2 but
> this hasn't helped.  I'm attempting to reproduce this using the dom4j
> API's.  In the meantime, I'm open to suggestions.

dom4j uses Jaxen (http://jaxen.org/) under the covers for XPath stuff,
so if you want to boil things down to original sources, I suggest...

1) Try a Document.selectNodes(...) through the dom4j API.

	If that fails...

2) Try XPath.selectNodes( doc ) through the Jaxen API.

At one point, we didn't have the union operator working right, but
I think it's been fixed for a while, and dom4j 1.2 should have
integrated the latest jaxen sources, I think.

James?

	-bob


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>