You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Brian S. Lloyd-Newberry" <ne...@yahoo.com> on 2002/06/04 00:55:33 UTC
DVSL: xpath choices in Transformer.java applyTemplates()
All,
Ran into a bit of a quagmire today when playing with DVSL (which rocks
BTW). I have a bit of XML like the following:
<section name="WACoder overview">
<p>
<A name="WACoder overview"/>
WACoder is a tool to allow human "coders" to answer sets of
questions about <define key="object">objects</define> with an
interface that can be viewed in most web browsers. The intended purpose of
the WACoder is to enable coding of web pages which have been archived.
</p>
...
</section>
Now I was trying to transform <p/> into something useful so that I
could get my nested <define/> node to render like I wanted it to (It
points to the glossary for the document, for those who care).
#match( "p" )
<p>
$context.applyTemplates("*")
</p>
#end
We'll since I didn't know XPath very well before today I didn't
realize that * meant all Element nodes. So after a spat of hair
pulling I ended up discovering the applyTemplates() method which
lovingly uses
"/*|@*|text()|comment()|processing-instruction()/descendant-or-self::*"
as it's preferred XPath. I was saved!
Actually I wasn't. I still didn't know XPath well enough... What I
really needed was "node()". That gave me all of the stuff I wanted in
the order I had specified it.
Now, since I have scientifically proved that I am inept at XPath, I
hesitate to make any suggestions, but might it make sense to use
"node()" in place of "*|@*|text()|comm ... r-self::*". One very nice
side effect of using "node()" is that the elements came back in the
order that I expected, whereas without it they did not.
Whatya think?
-Brian
==========
Brian S. Lloyd-Newberry
newbeb@yahoo.com
Software Engineer on way to many projects...
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: DVSL: xpath choices in Transformer.java applyTemplates()
Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 6/3/02 6:55 PM, "Brian S. Lloyd-Newberry" <ne...@yahoo.com> wrote:
> All,
>
> Ran into a bit of a quagmire today when playing with DVSL (which rocks
> BTW). I have a bit of XML like the following:
>
> <section name="WACoder overview">
> <p>
> <A name="WACoder overview"/>
> WACoder is a tool to allow human "coders" to answer sets of
> questions about <define key="object">objects</define> with an
> interface that can be viewed in most web browsers. The intended purpose of
> the WACoder is to enable coding of web pages which have been archived.
> </p>
>
> ...
>
> </section>
>
>
> Now I was trying to transform <p/> into something useful so that I
> could get my nested <define/> node to render like I wanted it to (It
> points to the glossary for the document, for those who care).
>
> #match( "p" )
> <p>
> $context.applyTemplates("*")
> </p>
> #end
>
> We'll since I didn't know XPath very well before today I didn't
> realize that * meant all Element nodes. So after a spat of hair
> pulling I ended up discovering the applyTemplates() method which
> lovingly uses
> "/*|@*|text()|comment()|processing-instruction()/descendant-or-self::*"
> as it's preferred XPath. I was saved!
Woah. I had to go to the code to review, but that isn't quite what it uses
- what it uses is
*|@*|text()|comment()|processing-instruction()
>
> Actually I wasn't. I still didn't know XPath well enough... What I
> really needed was "node()". That gave me all of the stuff I wanted in
> the order I had specified it.
The problem is in the union operator seems to be wacked - what happens is
that the nodes don't come back in document order when using '|'. The funny
part is that the Xpath spec seems to have left this requirement out - I
think people realized it was hard? :) Of course, it makes it somewhat
useless when processing things that you want in order (like text... :)
>
> Now, since I have scientifically proved that I am inept at XPath, I
> hesitate to make any suggestions, but might it make sense to use
> "node()" in place of "*|@*|text()|comm ... r-self::*". One very nice
> side effect of using "node()" is that the elements came back in the
> order that I expected, whereas without it they did not.
>
> Whatya think?
I have to admit that I was very surprised that applyTemplates("node()")
worked. I didn't think that it would, but indeed, a review of the Xpath
spec... My xpath is pretty weak as wlel.
I think that we are free to do what we want in DVSL - it's here so we can
build a tool that we need, not to conform to a spec.
So I think we should try this - it seems to be what people expect anyway.
It is certainly what I expect.
I just wonder if we will break anything?
--
Geir Magnusson Jr.
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>