使用XSLT解析HTML

时间:2017-07-11 10:54:59

标签: html xslt

我有一个像这样的html文件:

physicsBody

如果我应用此xslt:

<html lang="en,us">
    <head>
        <title>Welcome to the Oracle</title>
    </head>
    <body>
        <table width="100%" cellspacing="5" cellpadding="5" border="0">
            <tr>
                <td>
                    <h2>Welcome to the Oracle</h2>
                    <p>The following processes</p>
                    <ol>
                        <li>Process1</li>
                        <li>Process2</li>
                        <li>Process3</li>
                    </ol>
                </td>
            </tr>
        </table>
    </body>
</html>

我什么都没得到。

如果我试试这个:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:for-each select="/html/body/table/tr/td/ol/li">
                <xsl:value-of select="li"/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

然后得到这个:

处理1 处理1 处理1

我如何得到这个?

处理1 过程2 Process3

1 个答案:

答案 0 :(得分:1)

而不是

    <xsl:for-each select="/html/body/table/tr/td/ol/li">
            <xsl:value-of select="li"/>
    </xsl:for-each>

你想要

    <xsl:for-each select="/html/body/table/tr/td/ol/li">
            <xsl:value-of select="."/>
    </xsl:for-each>

for-each内部,上下文是li元素。