2
我們有一堆html頁面的文件,其中包含額外的xml元素(全部以我們的公司名稱'TLA'作爲前綴)爲我提供的舊程序提供數據和結構現在正在重寫。僅複製混合xml和HTML中的HTML
示例表:
<html >
<head>
<title>Highly Simplified Example Form</title>
</head>
<body>
<TLA:document xmlns:TLA="http://www.tla.com">
<TLA:contexts>
<TLA:context id="id_1" value=""></TLA:context>
</TLA:contexts>
<TLA:page>
<TLA:question id="q_id_1">
<table>
<tr>
<td>
<input id="input_id_1" type="text" />
</td>
</tr>
</table>
</TLA:question>
</TLA:page>
<!-- Repeat many times -->
</TLA:document>
</body>
</html>
我的任務是寫一個預處理器,將只複製html元素,完全與他們的屬性和內容到一個新文件。
像這樣:
<html >
<head>
<title>Highly Simplified Example Form</title>
</head>
<body>
<table>
<tr>
<td>
<input id="input_id_1" type="text" />
</td>
</tr>
</table>
<!-- Repeat many times -->
</body>
</html>
我已經採取了使用XSLT因爲這是我需要的是什麼extract the TLA elements爲不同的文件的方法。到目前爲止,這是我的XSLT有:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:mbl="http://www.mbl.com">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:template match="mbl:* | mbl:*/@* | mbl:*/text()"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
然而,這僅產生如下:
<html >
<head>
<title>Highly Simplified Example Form</title>
</head>
<body>
</body>
</html>
正如你可以看到TLA內的所有內容:文檔元素被排除在外。在XSLT中需要更改所有html而過濾掉TLA元素?
或者,有沒有更簡單的方法來解決這個問題?我知道幾乎每個瀏覽器都會忽略TLA元素,所以有什麼方法可以使用HTML工具或應用程序獲取我需要的內容?
我注意到這個小問題,它不輸出正確的HTML。請注意,自我關閉的輸入元素,這僅適用於xhtml。有沒有辦法獲得有效的HTML出來,因爲當我對真正的文檔(使用xsl:輸出html)運行它,這使得許多標籤未關閉? – 2013-04-09 08:27:23
我不明白你的評論的第二句話。如果您希望將其輸出爲html,則可以將'xsl:output'方法更改爲「html」。 – JLRishe 2013-04-09 17:54:06
我認爲這可能會更好地做一個完整的問題:http://stackoverflow.com/questions/15897500/closing-tags-when-extracting-html-from-xml – 2013-04-10 07:20:57