|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Using XSL for Serialization with Javascript.
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








