XmlDataSource.TransformArgumentList 屬性

定義

提供 XSLT 引數的清單,這些引數與 TransformTransformFile 屬性所定義的樣式表搭配使用,以執行 XML 資料的轉換。Provides a list of XSLT arguments that are used with the style sheet defined by the Transform or TransformFile properties to perform a transformation on the XML data.

public:
 virtual property System::Xml::Xsl::XsltArgumentList ^ TransformArgumentList { System::Xml::Xsl::XsltArgumentList ^ get(); void set(System::Xml::Xsl::XsltArgumentList ^ value); };
[System.ComponentModel.Browsable(false)]
public virtual System.Xml.Xsl.XsltArgumentList TransformArgumentList { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.TransformArgumentList : System.Xml.Xsl.XsltArgumentList with get, set
Public Overridable Property TransformArgumentList As XsltArgumentList

屬性值

XsltArgumentList

XsltArgumentList 物件,包含 XmlDataSource 控制項載入 XML 資料時,要套用至該 XML 資料的 XSLT 參數和物件。An XsltArgumentList object that contains XSLT parameters and objects to be applied to XML data when it is loaded by the XmlDataSource control. 預設值是 nullThe default value is null.

屬性

範例

下列程式碼範例示範如何使用 XmlDataSourceTreeView 控制項來顯示轉換後的 XML 資料。The following code example demonstrates how to use an XmlDataSource with a TreeView control to display transformed XML data. XML 轉換是使用屬性所指示的樣式表單來執行 TransformFileThe XML transformation is performed using the style sheet indicated by the TransformFile property. 此外,樣式表單會使用轉換引數,這些引數會在執行時間傳遞至物件中的資料來源控制項 XsltArgumentListAdditionally, the style sheet uses transform arguments that are passed to the data source control in an XsltArgumentList object at run time. 程式碼範例示範如何 XsltArgumentList Transforming 使用自訂事件處理常式來處理事件,以將傳遞給資料來源控制項。The code example demonstrates how to pass the XsltArgumentList to the data source control by handling the Transforming event with a custom event handler.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml.Xsl" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
private void TransformEventHandler(object sender, EventArgs e) {

  // Add a dynamic transformation argument.
  DateTime d = new DateTime();
  d = DateTime.Now.AddDays(20);

  // Create an XsltArgumentList.
  XsltArgumentList xslArg = new XsltArgumentList();
  xslArg.AddParam("purchdate", "", d.ToShortDateString());

  ((XmlDataSource) sender).TransformArgumentList = xslArg;
}
</script>

<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="bookswithdiscount.xsl"
        ontransforming="TransformEventHandler" />

        <!- 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="title"/>
          <asp:treenodebinding depth="3" datamember="chapter"
            textfield="name" valuefield="num"/>
        </databindings>
      </asp:treeview>

    </form>
  </body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml.Xsl" %>

<script runat="server">
Private Sub TransformEventHandler(sender As Object, e as EventArgs)

  ' Add a dynamic transformation argument.
  Dim d As New DateTime
  d = DateTime.Now.AddDays(20)

  'Create an XsltArgumentList.
  Dim xslArg As XsltArgumentList = New XsltArgumentList
  xslArg.AddParam("purchdate", "", d.ToShortDateString())

  Dim aXmlDataSource as XmlDataSource = CType(sender, XmlDataSource)
  aXmlDataSource.TransformArgumentList = xslArg

End Sub ' TransformEventHandler
</script>

<!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="bookswithdiscount.xsl"
        ontransforming="TransformEventHandler" />

        <!- 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="title"/>
          <asp:treenodebinding depth="3" datamember="chapter"
            textfield="name" valuefield="num"/>
        </databindings>
      </asp:treeview>

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

程式碼範例中的 XML 檔案包含下列資料:The XML file in the code example has the following data:

<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>  

XML 資料的轉換會使用下列樣式表單來執行。The transformation of the XML data is performed with the following style sheet.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
 <xsl:param name="purchdate"/>  
 <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"/>  
       Price: <xsl:value-of select="price"/>  
           15% discount if purchased by: <xsl:value-of select="$purchdate"/>        
     </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>  

備註

TransformArgumentList當引發事件時設定屬性, Transforming 以確保在將 xslt 轉換套用至 XML 資料時,可以使用 xslt 參數。Set the TransformArgumentList property when the Transforming event is raised to ensure the XSLT parameters are available at the time that the XSLT transformation is applied to the XML data.

如果 EnableCaching 屬性設定為, trueTransformArgumentList 已設定屬性,則當轉換引數清單中的參數變更時,快取專案不會自動失效。If the EnableCaching property is set to true and the TransformArgumentList property is set, the cache entries are not automatically invalidated when the parameters change in the transforms argument list. 在這種情況下,您必須撰寫程式碼,藉由設定屬性使快取失效 CacheKeyDependencyIn that case, you must write code to invalidate the cache by setting the CacheKeyDependency property.

適用於

另請參閱