如果你要轉成HTML格式,你有兩種選擇:
- 使用
pre
標籤準確地呈現在瀏覽器中的文本是。
- 使用一些高級XPath 2.0函數解析文本,並根據需要處理每個文本行。
這裏的第一個選項傻例如:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="MESSAGE/TranslationReport">
<html>
<body>
<pre>
<xsl:value-of select="."/>
</pre>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
在第二個選項,我們會分析你的文字與XPath 2.0中功能tokenize
,所有分割線和包裝每一個與eanted標籤。
這是愚蠢的例子:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="MESSAGE/TranslationReport">
<html>
<body>
<xsl:for-each select="tokenize(.,'\n')
[not(position()=(1,last()))]">
<p class="TranslationReport">
<xsl:value-of select=".[position()]"/>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
在第二種情況下,輸出將是:
<html>
<body>
<p class="TranslationReport">Translation Report</p>
<p class="TranslationReport">==================</p>
<p class="TranslationReport">Contains errors ? true</p>
<p class="TranslationReport">Contains warnings ? false</p>
<p class="TranslationReport">There are 9 entries in the report</p>
</body>
</html>
我能夠產生你正在尋找一個直XSL轉換的結果,使用例如http://www.shell-tools.net/index.php?op=xslt你如何渲染結果? – Brabster
+1好問題。 –