XML elements to JavaScript Array elements Conversion

Discussion in 'XML' started by P, Jul 7, 2006.

  1. P

    P Guest

    Hi,

    I am finding it little harder to get this done, kindly help me.
    I need to convert an XML file to a JavaScript file (Array) using XSLT,
    1. Can I use <xsl:eek:utput method="text">?
    2. I am suppose to convert the following pattern of XML to JavaScript
    file like the one given below.
    Input XML format:
    <links>
    <section1>
    <name>SearchEngines</name>
    <url>www.searchengines.com</url>
    <section2>
    <name>Google</name>
    <url>www.google.com</url>
    <section3>
    <name>Groups</name>
    <url>www.groups.google.com</url>
    </section3>
    <section3>
    <name>Mail</name>
    <url>www.gmail.com</url>
    </section3>
    </section2>
    <section2>
    <name>Yahoo</name>
    <url>www.yahoo.com</url>
    <section3>
    <name>Photos</name>
    <url>www.photos.yahoo.com</url>
    </section3>
    </section2>
    </section1> <!-- End of Section1 - I -->
    <section1>
    <name>Sample</name>
    <url>www.sample.com</url>
    <description>No section2 links are present for
    this.</description>
    </section1> <!-- End of Section1 - II -->
    <section1>
    <name>Tutorials</name>
    <url>www.tutorials.com</url>
    <section2>
    <name>XML</name>
    <url>www.tutorials.com/xml</url>
    <section3>
    <name>XSLT</name>
    <url>www.tutorials.com/xml/xslt</url>
    </section3>
    </section2>

    </section1> <!-- End of Section1 - III -->
    </links>

    Output JavaScript File: ( we need to make the values of the elements as
    arrays, naming for Each section's array has to be like it is given
    here.)

    //Section1 Entries
    Array1 = [
    [170, 120 // Few Hardcoded values
    ],
    ["SearchEngines","www.searchengines.com",1,0,1], // few values are
    hardcoded here 1,0,1
    ["Sample","www.sample.com",1,0,1],
    ["Tutorials","www.tutorials.com",1,0,1],
    ]

    //Section2 entries of Section1 I
    Array1_1 = [
    [],
    ["Google","www.google.com",1,0,0], // few values are hardcoded here
    1,0,0
    ["Yahoo","www.yahoo.com",1,0,0],
    ]

    //Section2 entries of Section1 II - when description is present for
    Section 1, it should be given as section 2 link as well
    Array1_2 = [
    [],
    ["No section2 links are present for this.","www.sample.com",1,0,0],
    ]

    //Section2 entries of Section1 III
    Array1_3 = [
    [],
    ["XML","www.tutorials.com/xml",1,0,0],
    ]

    // Section 3 entries

    Array1_1_1 = [
    [],
    ["Groups","www.groups.google.com",1,0,0], // few values are hardcoded
    here 1,0,0
    ["Mail","www.gmail.com",1,0,0],
    ]

    Kindly let me know, how to do this kind of conversion from XML to
    JavaScript using XSLT

    Thank you,

    Regards,
    Annbu P
     
    P, Jul 7, 2006
    #1
    1. Advertising

  2. P wrote:
    > 1. Can I use <xsl:eek:utput method="text">?


    Yes.

    > Kindly let me know, how to do this kind of conversion from XML to
    > JavaScript using XSLT


    There's a lot of good XSLT instructional information on the web; my
    standard recommendations are the tutorials and articles on IBM's
    DeveloperWorks website (http://www.ibm.com/xml) and, for the stuff that
    isn't immediately obvious after reading those articles, the XSLT FAQ at
    http://www.dpawson.co.uk/xsl/index.html

    (Folks here, and on most mailing lists, will be much more willing to
    answer specific questions than general requests that we do your homework
    for you...)
     
    Joe Kesselman, Jul 7, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hari Om
    Replies:
    1
    Views:
    472
    Martin SChukrazy
    Mar 2, 2004
  2. Jure Sah

    XML to XML conversion

    Jure Sah, Aug 14, 2005, in forum: XML
    Replies:
    5
    Views:
    450
    Peter Flynn
    Aug 16, 2005
  3. Ultrus
    Replies:
    4
    Views:
    2,738
    Stefan Behnel
    Aug 30, 2007
  4. Chris Seberino
    Replies:
    3
    Views:
    760
    Stefan Behnel
    Jun 12, 2009
  5. , India
    Replies:
    2
    Views:
    488
    Fraser Ross
    Sep 15, 2009
Loading...

Share This Page