tags:

views:

217

answers:

1

I have the following XSL translator that is is being used to generate some XHTML. The generated XHTML is then parsed as XML in C# so it can be injected into another XHTML document. The trouble is that the XHTML that is outputted from the XLS does not have a root XML node, just sibling nodes (< table > elements). I tried adding the div manually, but I get the error System.Xml.Xsl.XslLoadException: Top-level element 'div' may not have a null namespace. How can I add this using XSL so that a div wraps all the < table >'s?

<?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"&gt;

  <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>
+2  A: 

You should to add your <div> here:

<xsl:template match="/NewDataSet">
  <div>
    <xsl:apply-templates select="QueryResultData[...]"/>
  </div>
</xsl:template>
Rubens Farias