PDA

View Full Version : Can I concatenate xpath values?


TripleToe
05-19-2004, 03:52 PM
I'm a little new to the Laszlo syntax so maybe someone can help me out.

My data looks like this

<teachers>
<teacher id="1">
<firstname>John</firstname>
<lastname>Doe</lastname>
</teacher>
<teacher id="2">
<firstname>Jane</firstname>
<lastname>Doe</lastname>
</teacher>
</teachers>

I have a list and I want the list text to display both the first and last names.

I was trying something like this to concatenate the two xpath values:

<textlistitem width="300" datapath="teachersdata:/teachers/teacher/" text='$path{"firstname/text()"} + $path{"lastname/text()"}' value='$path{"@id"}' />

But this doesn't work. Does anyone know how to combine the firstname and lastname nodes to set the text attribute for the list?

Thanks

antun
05-20-2004, 09:13 AM
For something like this you can build up the string when the text field sends its ondata event:


<canvas debug="true">

<dataset name="myds">
<teachers>
<teacher id="1">
<firstname>John</firstname>
<lastname>Doe</lastname>
</teacher>
<teacher id="2">
<firstname>Jane</firstname>
<lastname>Doe</lastname>
</teacher>
</teachers>
</dataset>

<text datapath="myds:/teachers[1]/teacher[1]">
<method event="ondata">
var str = this.datapath.xpathQuery( "firstname/text()" )
+ " " + this.datapath.xpathQuery( "lastname/text()" );
this.setText( str );
</method>
</text>

</canvas>


-Antun

TripleToe
05-20-2004, 09:48 AM
Thanks for the reply. The only problem here is that I am using a textlistitem component rather than just text. The textlistitem component doesn't have a setText() method. I tried this:

<textlistitem width="300" datapath="teachersdata:/teachers/teacher" value='$path{"@id"}'>
<method event="ondata">
debug.write("ondata");
var fullname = this.datapath.xpathQuery("firstname/text()") + " " + this.datapath.xpathQuery("lastname/text()")
debug.write(fullname);
this.text = fullname;
</method>
</textlistitem>

The debug statement shows the correct result, but I'm not able to actually set the text value of the textlistitem using the script. Any suggestions on this?

Thanks again.

antun
05-20-2004, 10:54 AM
this.text = "foo" won't work - the ontext event won't be sent, so the textlistitem won't have cause to update.

If an attribute doesn't have a setter method in LZX, you can always use setAttribute:

this.setAttribute( "text", "some text" );

... which does send the ontext event.

-Antun

TripleToe
05-20-2004, 11:05 AM
Excellent! That is just what I was looking for. Thanks so much!