我有以下用于生成一些XHTML的XSL转换器。然后,生成的XHTML在C#中被解析为XML,因此可以将其注入另一个XHTML文档中。问题是从XLS输出的XHTML没有根XML节点,只有兄弟节点(< table>元素)。我尝试手动添加div,但是我收到错误System.Xml.Xsl.XslLoadException:顶级元素'div'可能没有null命名空间。如何使用XSL添加它,以便div包装所有<表>的?
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="msxsl"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="groups" match="/NewDataSet/QueryResultData" use="MemberReportGroup4Description" />
<xsl:template match="/NewDataSet">
<xsl:apply-templates select="QueryResultData[generate-id() = generate-id(key(''groups'', MemberReportGroup4Description)[1])]"/>
</xsl:template>
<xsl:template match="stock">
</xsl:template>
<div>
<xsl:template match="QueryResultData">
<table id="{MemberReportGroup4Description}">
<tr>
<th colspan="6" scope="col"><div align="left"><h1>Store #<xsl:value-of select="MemberReportGroup4Description"/></h1></div></th>
</tr>
<tr class="heading">
<th colspan="2" scope="col">User Name</th>
<th scope="col">Viewed Percentage</th>
<th scope="col">Enrollment Date</th>
<th scope="col">Status</th>
<th scope="col">Requirement Completion Date</th>
</tr>
<xsl:for-each select="key(''groups'', MemberReportGroup4Description)">
<tr>
<td><xsl:value-of select="MemberFirstName"/></td>
<td><xsl:value-of select="MemberLastName"/></td>
<td><xsl:value-of select="ViewedPercentage"/></td>
<td><xsl:value-of select="EnrollmentDate"/></td>
<td><xsl:value-of select="Status"/></td>
<td><xsl:value-of select="MemberReportGroup4Description"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>\
</div>
</xsl:stylesheet>
答案 0 :(得分:3)
您应该在此处添加<div>
:
<xsl:template match="/NewDataSet">
<div>
<xsl:apply-templates select="QueryResultData[...]"/>
</div>
</xsl:template>