使用XSLT重新创建网页?

时间:2011-05-27 19:46:42

标签: html xml

我不知道是否可以将外部网页打开到iframe中,我想知道是否可以“读取”外部网页HTML代码(如DIV标签)以及内容以创建带有XSLT的新HTML页面?

1 个答案:

答案 0 :(得分:1)

以下链接是一个使用jQuery从服务器读取XML文件并在页面上显示数据的示例:

重要的是要注意返回的数据是严格的XML。你也可以返回JSON。

我强烈建议使用框架(例如jQuery)来检索数据,而不是直接使用XMLHttpRequest,因为需要考虑许多跨浏览器问题。另外,一旦检索到数据,jQuery就有一个很好的API来操作DOM。

修改

下面是一个未经测试的示例,说明在检索HTML文件时如何执行与上述示例类似的操作。请注意,我正在浏览一些重要的jQuery函数。如果你决定走这条路,你应该阅读Getting Started教程。特别是关于选择器和操纵的位。

// the get() function is used to retrieve a file
jQuery.get(

    // the filename on the server is "somefile.html"
    "somefile.html",

    // the contents of "somefile.html" are passed to this function
    function(html) {

        // use jQuery to find all <p> tags and append them
        // to <div id="resultContainer">
        jQuery(html).find("p").each(function(ix, p) {
            jQuery("#resultContainer").append(p);
        });
    },

    // lets jQuery know the file type we are retrieving is an HTML file
    "html"
);