views:

233

answers:

0

I'm writing a custom web part that extends DataFormWebPart.

    public class MyCustomWebPart : DataFormWebPart{
        // other methods

        public override void DataBind()
        {
            XmlDataSource source =
                new XmlDataSource() { Data = @"
                        <Person>
                            <name cap='true'>Bryan</name>
                            <occupation>student</occupation>
                        </Person>
                        "
                };

            DataSources.Add(source);

            base.DataBind();
        }
     }

The only noticeable thing I do is overriding the DataBind() method, where I use xml as the data source.

After I deploy the web part, I set the following XSL to it:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
    <xmp>
      <xsl:copy-of select="*"/>
    </xmp>
  </xsl:template>
</xsl:stylesheet>

This xsl will surround the input xml with a tag . So I expected the web part to display the original xml data as I wrote in C# code behind. But what shows up in the web part is this:

  <Person>
    <name cap="true" />
    <occupation />
  </Person>

All the values within the inner-most tags disappear.

What's going on? Can anybody help me?

Thanks.