我正在做一個非常簡單的xslt將html頁面轉換爲xml文件。XHTML到XML XSLT轉換
但在我看來,起點對我來說並不那麼簡單。我的第一個目標是將<html>
標記轉換爲<topic>
標記。
我做了以下XSLT:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="html">
<topic>
<xsl:text> Conversion Test</xsl:text>
</topic>
</xsl:template>
不過,現在我運行這個XSLT後,結果XML是純粹原始的HTML頁面的內容相同的,好像是第三個模板匹配,我寫(匹配<html>
標籤)永遠不會被擊中。
HTML源代碼看起來像:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>..</head>
<body>...</body>
</html>
專家能幫助我一點嗎?
你能舉一個你的html的例子嗎? (特別是任何命名空間像'xmlns =「http://www.w3.org/1999/xhtml」') –
@DevNull,我更新了我的問題與源HTML – Kevin
謝謝。好問題+1 –