我转换的混合html和使用XSLT样式表,只提取HTML元素的XML文档。
源文件:
<?xml version="1.0" encoding="utf-8" ?>
<html >
<head>
<title>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>
<table id="table_logo" style="display:inline">
<tr>
<td height="20" align="middle">Big Title Goes Here</td>
</tr>
<tr>
<td align="center">
<img src="logo.jpg" border="0"></img>
</td>
</tr>
</table>
<TLA:page>
<TLA:question id="q_id_1">
<table id="table_id_1">
<tr>
<td>Label text goes here</td>
<td>
<input id="input_id_1" type="text"></input>
</td>
</tr>
</table>
</TLA:question>
</TLA:page>
<!-- Repeat many times -->
</TLA:document>
</body>
</html>
样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:TLA="http://www.TLA.com" exclude-result-prefixes="TLA">
<xsl:output method="html" indent="yes" version="4.0" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()" priority="-2">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- This element-only identity template prevents the
TLA namespace declaration from being copied to the output -->
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<!-- Pass processing on to child elements of TLA elements -->
<xsl:template match="TLA:*">
<xsl:apply-templates select="*" />
</xsl:template>
</xsl:stylesheet>
输出:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simplified Example Form</title>
</head>
<body>
<table id="table_logo" style="display:inline">
<tr>
<td height="20" align="middle">Big Title Goes Here</td>
</tr>
<tr>
<td align="center"><img src="logo.jpg" border="0"></td>
</tr>
</table>
<table id="table_id_1">
<tr>
<td>Label text goes here</td>
<td><input id="input_id_1" type="text"></td>
</tr>
</table>
</body>
</html>
但是有在元,IMG和输入元件没有被正确关闭的问题。 所以就输出HTML和版本4.0,因为我知道自己应该正确输出HTML:我已经设置了xsl。
我猜,有需要在第一个XSL了微妙的变化:模板/ XSL:复制指令,但我的XSLT技能是非常有限的。
有什么需要改变作出拿到标记来正确关闭?
PS我不知道是否有不同的工具/解析器,但我使用Visual Studio 2012来调试样式表,这样我可以看到任何变化立竿见影的效果之间的差异。