XmlDataSource.TransformFile Właściwość

Definicja

Określa nazwę pliku extensible Stylesheet Language (XSL) pliku (xsl), który definiuje przekształcenie XSLT do wykonania na danych XML zarządzanych przez kontrolkę XmlDataSource .

public:
 virtual property System::String ^ TransformFile { System::String ^ get(); void set(System::String ^ value); };
public virtual string TransformFile { get; set; }
member this.TransformFile : string with get, set
Public Overridable Property TransformFile As String

Wartość właściwości

Bezwzględna ścieżka fizyczna lub ścieżka względna pliku arkusza stylów XSL, który definiuje przekształcenie XML do wykonania na danych zawartych we właściwościach Data lub DataFile . Wartość domyślna to Empty.

Wyjątki

Trwa ładowanie dokumentu.

Przykłady

W poniższym przykładzie kodu pokazano, jak używać kontrolki XmlDataSource i TreeView kontrolki do wyświetlania przekształconych danych XML w formularzu internetowym. Przekształcenie jest wykonywane przy użyciu arkusza stylów wskazanego TransformFile przez właściwość . Opcjonalnie można podać argumenty przekształcenia dla arkusza stylów przy użyciu elementu XsltArgumentList. Aby uzyskać więcej informacji, zobacz TransformArgumentList właściwość .

<%@ 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>ASP.NET Example</title>
</head>
<body>

    <form id="form1" runat="server">
      <asp:XmlDataSource
        id="XmlDataSource1"
        runat="server"
        datafile="bookstore.xml"
        transformfile="bookstore.xsl"/>

      <!- TreeView uses hierachical data, so the
          XmlDataSource uses an XmlHierarchicalDataSourceView
          when a TreeView is bound to it. -->

      <asp:treeview
        id="TreeView1"
        runat="server"
        datasourceid="XmlDataSource1">
        <databindings>
          <asp:treenodebinding depth="1" datamember="genre"
             textfield="name" valuefield="name"/>
          <asp:treenodebinding depth="2" datamember="book"
            textfield="title" valuefield="ISBN"/>
          <asp:treenodebinding depth="3" datamember="chapter"
            textfield="name" valuefield="num"/>
        </databindings>
      </asp:treeview>

    </form>
    
  </body>
</html>
<%@ Page Language="VB" %>
<!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>ASP.NET Example</title>
</head>
<body>

    <form id="form1" runat="server">
      <asp:xmldatasource
        id="XmlDataSource1"
        runat="server"
        datafile="bookstore.xml"
        transformfile="bookstore.xsl"/>

      <!- TreeView uses hierachical data, so the
          XmlDataSource uses an XmlHierarchicalDataSourceView
          when a TreeView is bound to it. -->

      <asp:treeview
        id="TreeView1"
        runat="server"
        datasourceid="XmlDataSource1">
        <databindings>
          <asp:treenodebinding depth="1" datamember="genre"
             textfield="name" valuefield="name"/>
          <asp:treenodebinding depth="2" datamember="book"
            textfield="title" valuefield="ISBN"/>
          <asp:treenodebinding depth="3" datamember="chapter"
            textfield="name" valuefield="num"/>
        </databindings>
      </asp:treeview>

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

Plik XML w przykładzie kodu zawiera następujące dane:

<bookstore>  
   <genre name="fiction">  
     <book ISBN="0000000000">  
       <title>Secrets of Silicon Valley</title>  
       <price>12.95</price>  
       <chapters>  
         <chapter num="1" name="Introduction" />             
         <chapter num="2" name="Body" />            
         <chapter num="3" name="Conclusion" />  
       </chapters>  
     </book>  
   </genre>  
   <genre name="novel">  
     <book genre="novel" ISBN="1111111111">  
       <title>Straight Talk About Computers</title>  
       <price>24.95</price>  
       <chapters>  
         <chapter num="1" name="Introduction" />   
         <chapter num="2" name="Body" />  
         <chapter num="3" name="Conclusion" />  
       </chapters>  
     </book>  
   </genre>  
</bookstore>  

Arkusz stylów XSL wykonujący transformację XML ma następującą strukturę:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
 <xsl:template match="bookstore">  
   <bookstore>  
     <xsl:apply-templates select="genre"/>  
   </bookstore>  
 </xsl:template>  
 <xsl:template match="genre">  
   <genre>  
     <xsl:attribute name="name">  
       <xsl:value-of select="@name"/>  
     </xsl:attribute>  
     <xsl:apply-templates select="book"/>  
   </genre>  
 </xsl:template>  
 <xsl:template match="book">  
   <book>  
     <xsl:attribute name="ISBN">  
       <xsl:value-of select="@ISBN"/>  
     </xsl:attribute>  
     <xsl:attribute name="title">  
       <xsl:value-of select="title"/>  
     </xsl:attribute>  
     <xsl:attribute name="price">  
       <xsl:value-of select="price"/>  
     </xsl:attribute>  
     <xsl:apply-templates select="chapters/chapter" />  
   </book>  
 </xsl:template>  
 <xsl:template match="chapter">  
   <chapter>  
     <xsl:attribute name="num">  
       <xsl:value-of select="@num"/>  
     </xsl:attribute>  
     <xsl:attribute name="name">  
       <xsl:value-of select="@name"/>  
     </xsl:attribute>  
     <xsl:apply-templates/>  
   </chapter>  
 </xsl:template>  
</xsl:stylesheet>  

Uwagi

TransformFile Jeśli właściwości i Transform są ustawione, TransformFile właściwość ma pierwszeństwo, a dane w pliku arkusza stylów XSL (.xsl) są używane zamiast elementów arkusza stylów określonych we Transform właściwości . Jeśli wyrażenie XPath jest ustawione przy użyciu XPath właściwości , jest stosowane po przekształceniu danych XML.

Jeśli zmienisz wartość Transform właściwości, DataSourceChanged zdarzenie zostanie zgłoszone. Jeśli buforowanie jest włączone i zmieniasz wartość Transform, pamięć podręczna zostanie unieważniona.

Uwaga

Klasa XmlDataSource używa przestarzałej XslTransform klasy do wykonywania przekształceń XSL. Jeśli chcesz użyć funkcji arkusza stylów, które zostały wprowadzone po XslTransform wycofaniu klasy, zastosuj przekształcenia ręcznie przy użyciu XslCompiledTransform klasy .

Dotyczy

Zobacz też