Export (0) Print
Expand All

XmlDataSource.Transform Property

Gets or sets a block of Extensible Stylesheet Language (XSL) data that defines an XSLT transformation to be performed on the XML data managed by the XmlDataSource control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[TypeConverterAttribute("System.ComponentModel.MultilineStringConverter,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] 
public virtual string Transform { get; set; }
/** @property */
public String get_Transform ()

/** @property */
public void set_Transform (String value)

public function get Transform () : String

public function set Transform (value : String)

Not applicable.

Property Value

A string of inline XSL that defines an XML transformation to be performed on the data contained in the Data or DataFile properties. The default value is String.Empty.

Exception typeCondition

InvalidOperationException

The document is loading.

In declarative scenarios, the Transform property is specified as a multiline inner property of the XmlDataSource object. An inner property is compatible with XSL style sheet data, because it enables you to format the style sheet in any way and ignore character padding issues such as padding quote characters.

If both the TransformFile and Transform properties are set, the TransformFile property takes precedence and the data in the XSL style sheet file (.xsl) is used instead of the style sheet elements specified in the Transform property. If an XPath expression is set using the XPath property, it is applied after the XML data is transformed.

If you change the value of the Transform property, the DataSourceChanged event is raised. If caching is enabled and you change the value of Transform, the cache is invalidated.

The following code example demonstrates how to use an XmlDataSource control with a templated Repeater control to display transformed XML data. The style sheet that performs the transformation is defined inline by the Transform property of the data source control.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Order</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:XmlDataSource
        runat="server"
        id="XmlDataSource1"
        DataFile="order.xml" >
        <Transform>
          <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:template match="orders">
            <orders>
              <xsl:apply-templates select="order"/>
            </orders>
          </xsl:template>
          <xsl:template match="order">
            <order>
            <customer>
              <id>
                <xsl:value-of select="customer/@id"/>
              </id>
              <firstname>
                <xsl:value-of select="customername/firstn"/>
              </firstname>
              <lastname>
                <xsl:value-of select="customername/lastn"/>
              </lastname>
            </customer>
            </order>
          </xsl:template>
          </xsl:stylesheet>
        </Transform>
      </asp:XmlDataSource>

      <asp:Repeater
        runat="server"
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
            <h2>Order</h2>
            <table>
              <tr>
                <td>Customer</td>
                <td style="color:Blue"><%# XPath ("orders/order/customer/id") %></td>
                <td><%# XPath ("orders/order/customer/firstname") %></td>
                <td><%# XPath ("orders/order/customer/lastname") %></td>
              </tr>
            </table>
            <hr />
        </ItemTemplate>
    </asp:Repeater>

  </form>
  </body>
</html>

<%@ Page Language="VJ#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Order</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:XmlDataSource
        runat="server"
        id="XmlDataSource1"
        DataFile="order.xml" >
        <Transform>
          <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:template match="orders">
            <orders>
              <xsl:apply-templates select="order"/>
            </orders>
          </xsl:template>
          <xsl:template match="order">
            <order>
            <customer>
              <id>
                <xsl:value-of select="customer/@id"/>
              </id>
              <firstname>
                <xsl:value-of select="customername/firstn"/>
              </firstname>
              <lastname>
                <xsl:value-of select="customername/lastn"/>
              </lastname>
            </customer>
            </order>
          </xsl:template>
          </xsl:stylesheet>
        </Transform>
      </asp:XmlDataSource>

      <asp:Repeater
        runat="server"
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
            <h2>Order</h2>
            <table>
              <tr>
                <td>Customer</td>
                <td style="color:Blue"><%# XPath ("orders/order/customer/id") %></td>
                <td><%# XPath ("orders/order/customer/firstname") %></td>
                <td><%# XPath ("orders/order/customer/lastname") %></td>
              </tr>
            </table>
            <hr />
        </ItemTemplate>
    </asp:Repeater>

  </form>
  </body>
</html>

The XML file in the code example has the following data:

<?xml version="1.0" encoding="iso-8859-1"?>
 <orders>
   <order>
     <customer id="12345" />
     <customername>
         <firstn>Todd</firstn>
         <lastn>Rowe</lastn>
     </customername>
     <transaction id="12345" />
     <shipaddress>
         <address1>1234 Tenth Avenue</address1>
         <city>Bellevue</city>
         <state>Washington</state>
         <zip>98001</zip>
     </shipaddress>
     <summary>
         <item dept="tools">screwdriver</item>
         <item dept="tools">hammer</item>
         <item dept="plumbing">fixture</item>
     </summary>
   </order>
</orders>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft