Javascript 如何使用XSLT从.js文件中提取链接

Javascript 如何使用XSLT从.js文件中提取链接,javascript,xslt,Javascript,Xslt,我有一个.js文件。这是一个javascript文件,文本如下所示。我想提取所有href URL并将它们添加到循环中的一个变量中,以便进一步处理。我该怎么做?非常感谢 document.write('<tr bgcolor="#6691BC">'); document.write('<td width="15" height="25">&nbsp;</td>'); document.write('<td width="690" height

我有一个.js文件。这是一个javascript文件,文本如下所示。我想提取所有href URL并将它们添加到循环中的一个变量中,以便进一步处理。我该怎么做?非常感谢

 document.write('<tr bgcolor="#6691BC">'); document.write('<td
 width="15" height="25">&nbsp;</td>'); document.write('<td width="690"
 height="25" class="headertext">');

 document.write('<a href="../myspace.com/index.html" class="headerLink"
 style="color: #ffffff;">My Space</a>&nbsp;&nbsp;|&nbsp;&nbsp;');

 document.write('<a href="../technotes.com/index.html"
 class="headerLink" style="color: #ffffff;">Tech
 Notes</a>&nbsp;&nbsp;|&nbsp;&nbsp;');

 document.write('<td width="15" height="25">&nbsp;</td>');
 document.write('</tr>');
document.write(“”);文件。写(“”);文件。写(“”);
文件。写(“|”);
文件。写(“|”);
文件。写(“”);
文件。写(“”);

我将采用另一种方法-首先将html转换为单个xhtml字符串(请注意缺少的
,需要将
&
转义为

输出:

'../myspace.com/index.html','../technotes.com/index.html',

XSLT无法轻松解析Javascript。这是做这项工作的错误工具

以下是您可以采用的一些方法:

(1) 运行javascript,捕获生成的文档,然后对其使用XSLT。如果文档不是格式良好的XML,这可能会很麻烦

(2) 使用正则表达式,例如grep、perl-e、Javascript匹配函数


(3) 运行javascript,然后使用document.querySelectorAll('*[href]')获取href和工作表单中的所有元素

XSLT不是javascript解析器,任意JS是无效的XML。XSLT可以解决河内塔问题,所以我不认为子字符串匹配超出了它的能力,但这并不容易,也不漂亮…-1 XSLT仅适用于XML。
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    <xsl:template match="/">
        <xsl:apply-templates select="//a[@href]"></xsl:apply-templates>
    </xsl:template>

    <xsl:template match="a">'<xsl:value-of select="@href"/>',</xsl:template>
</xsl:stylesheet>
'../myspace.com/index.html','../technotes.com/index.html',