PDA

View Full Version : xpath query


jocsch
10-13-2004, 12:53 AM
Hi everybody,
I want to show a xml nested tree in a "flat view" (everything on the same level, no tree). I thought I would be able to do this with the "//element" xpath selector which should simply select all elements in the tree (even if they are at different levels, according to the xpath doc).
But doing so shows only the first level elements. Please have look at the example. May be I'm doing the //hobbit at the wrong place (using laszlo the first time).


<canvas width="450" height="250">
<include href="lz/tree.lzx"/>

<dataset name="ancestors">
<hobbit name="Frodo">
<hobbit name="Drogo">
<hobbit name="Fosco" grandparent="true"/>
<hobbit name="Bolger, Ruby" grandparent="true"/>
</hobbit>
<hobbit name="Brandybuck, Primula">
<hobbit name="Brandybuck, Gorbadoc" grandparent="true"/>
<hobbit name="Took, Mirabella" grandparent="true"/>
</hobbit>
</hobbit>
<hobbit name="teat"/>
</dataset>

<view x="20" y="20" layout="axis: x; spacing: 10">
<!-- flat tree -->
<view datapath="ancestors:/" bgcolor="#00bb00" layout="axis: y;spacing: 5">
<view datapath="//hobbit">
<text datapath="@name" />
</view>
</view>


<!-- data replicated tree -->
<view width="200" height="200">
<tree datapath="ancestors:/" icon="null" showroot="false">
<tree datapath="*" icon="null" text="$path{'@name'}"
isleaf="$path{'@grandparent'}"/>
</tree>
</view>
</view>
</canvas>


Thanks,
Markus

jocsch
10-13-2004, 05:03 AM
I found the solution on my own a few posts earlier:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=252&highlight=recursor

"//element" is not yet supported in laszlo.

jocsch
10-13-2004, 12:36 PM
After solving the display problem, I run into another one. How can I determine the depth of a node:

<item> will be 1
<item> will be 2
<item/> will be 3
<item/> will be 3
</item>
</item>

I tried a xpathQuery, but that doesn't work out:

Debug.write(this.datapath.xpathQuery('count(ancest or-or-self::*)'));

And I also tried to count each recursive loop, but that also leads to wrong results, may be
I don't fully understand the visibility of the attributes:

<class name="rec">
<attribute name="depth" value="1"/>
...
<rec datapath="*" depth="${this.depth+1}"/>
</class>

This produces only 1 and 3 values (even if there should be a 2).

Any idea?

Thanks,
Markus