Subject: Re: Using XSL for Serialization with Javascript. From: Robert Koberg <rob@xxxxxxxxxx> Date: Tue, 07 Nov 2000 18:16:53 -0800 |
> 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@xxxxxxxxxxx"; > 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@xxxxxxxxxxx</email> </person> <person> <name>Sometwo</name> <email>Sometwo@xxxxxxxxxxx</email> </person> <person> <name>Somethree</name> <email>Somethree@xxxxxxxxxxx</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@xxxxxxxxxxx; aContact[1].name = "Sometwo"; aContact[1].email = "mailto:sometwo@xxxxxxxxxxx; aContact[2].name = "Somethree"; aContact[2].email = "mailto:somethree@xxxxxxxxxxx; list.addContact(aContact); hth XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Using XSL for Serialization with Ja, Adam Van Den Hoven | Thread | RE: Using XSL for Serialization wit, Adam Van Den Hoven |
Re: xsl:variable {RE: XSL to handle, Mike Brown | Date | RE: xsl:variable {RE: XSL to handle, Xu, Xiaocun |
Month |