This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Using XSL for Serialization with Javascript.
- To: xsl-list at mulberrytech dot com
- Subject: Re: Using XSL for Serialization with Javascript.
- From: Robert Koberg <rob at koberg dot com>
- Date: Tue, 07 Nov 2000 18:16:53 -0800
- References: <00BB1956AE40D411B5B60050DA27311F121B8F@mail1.bluezone.net>
- Reply-To: xsl-list at mulberrytech dot com
> Here's an example of what I mean. Lets say that I have a mailinglist
object
> that is a collection of contact objects. We might create such a object in
> Javascript with something like:
>
> function setup() {
> var list = new MailingList();
> var aContact
> for(var x = 0; x<20; x++) {
> aContact = new Contact();
> aContact.name = "Someone";
> aContact.email = "someone@someone.com";
> list.addContact(aContact);
> }
> }
(Note: I have not tried the code below)
you could use XSL to write out the javascript object
the XML:
<people>
<person>
<name>Someone</name>
<email>Someone@someone.com</email>
</person>
<person>
<name>Sometwo</name>
<email>Sometwo@someone.com</email>
</person>
<person>
<name>Somethree</name>
<email>Somethree@someone.com</email>
</person>
</people>
the XSL:
<xsl:template match="people">
<script>
var list = new MailingList();
var aContact
<xsl:apply-templates/>
list.addContact(aContact);
</script>
</xsl:template>
<xsl:template match="person">
<xsl:variable name="i" select="position()-1"/>
aContact[$i].name = "<xsl:value-of select="name"/>";
aContact[$i].email = ""<xsl:value-of select="email"/>";
</xsl:template>
the result could look like:
var list = new MailingList();
var aContact
aContact[0].name = "Someone";
aContact[0].email = "mailto:someone@someone.com;
aContact[1].name = "Sometwo";
aContact[1].email = "mailto:sometwo@someone.com;
aContact[2].name = "Somethree";
aContact[2].email = "mailto:somethree@someone.com;
list.addContact(aContact);
hth
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list