Transform XML with multiple XSL files

后端 未结 3 2152
一生所求
一生所求 2021-02-19 02:00

I have some XML that I\'d like to transform into HTML using a number of XSL files. These XSL files are all related through xsl:import and xsl:include statements, and all require

3条回答
  •  攒了一身酷
    2021-02-19 02:46

    I would recommend using jquery to import and style the XML.

    Something like this would allow you to import the XML whenever a function is called (a function linked to a keypress or a refresh button or even a timer.)

    $.ajax({
        type: "GET",
        url: "FILENAME.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('site').each(function(){ //finds parent node
                var id = $(this).attr('id'); //id of parent node
                var title= $(this).find('title').text();  //finds title node within parent node
                var url = $(this).find('url').text(); //finds URL node within parent node
                var description = $(this).find('descr').text(); //etc...
                var img = $(this).find('img').text(); //etc...
    
                // Creates div with id of parent node (for individual styling)
                $('

    And the XML would look something like this:

    
     http://blah.com
     imgs/image1.png
     this is a description
     Title
    
    
    
     http://filler.com
     imgs/image2.jpg
     this is another description
     Title 2
    
    

    Of course instead of importing to a div you could import the XML to a table or any other type of HTML element.

提交回复
热议问题