PDA

View Full Version : help! how to put info from a dataset into a url?


whisperstorm
10-06-2003, 09:40 PM
I have information in a dataset that I'm trying to use to construct a URL. it's made up of static components as well as dynamic parts... All the tutorials talk about is setting datasets on text elements, but I need something like this:


some text

The text inside the URL is also fetched from the dataset, but I can get that, I just cannot figure out how to set values of a dataset to things like HREF ... plus its even more complicated since I need to sort of "construct" the url.

so say i had 3 tags in a dataset A B C
<wrapper>
<A>somestuff</A>
<B>someotherstuff</B>
<C>morestuff</C>
</wrapper>
and I wanted to create a url in an anchor tag:

[a href="http://www.somesite.com/"+A/text()+"/foobar?baz="+B/text() ... etc.

antun
10-08-2003, 03:45 PM
If you just want to retrieve a value from the XML to use in script (from where you could concatanate it into a URL of your choice), then you could use a datapointer tag:


<datapointer xpath="myds:/foo/bar">
<method event="ondata">
var text_node = this.getXPath( 'text()' );
global_url = "http://xxx?bar=" + text_node;
</method>
</datapointer>


The above method is good for retrieving a single piece of information once (i.e. when the data in the dataset returns, or is updated).

If you need to get to data relative to a particular view that's been replicated (and already has a datapath) you could call its datapath's getXPath() method:


<dataset ...>
<albums>
<album album_title="foo">
<song ... />
<song ... />
<song ... />
</album>
<album album_title="bar">
<song ... />
<song ... />
<song ... />
</album>

</albums>
</dataset>
...
<view datapath="album">
<view datapath="song">
<method event="onclick">
var songTitle = this.datapath.getXPath( '../@album_name' );
debug.write( 'This song is part of: ' + songTitle );
</method>
</view>
</view>
...


... here we're getting the view's datapath is song, but we need the album's name, so we're going up one level in the data hierarchy based on the datapath of the song, and getting that node's album_name attribute.

-Antun