XmlDataSource.TransformArgumentList プロパティ

定義

XSLT 引数リストを提供します。この引数リストは、XML データに対する変換を実行するために、Transform プロパティまたは TransformFile プロパティで定義されたスタイル シートと組み合わせて使用されます。

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 コントロールが XML データを読み込むときに適用される XSLT パラメーターおよびオブジェクトを保持する XmlDataSource オブジェクト。 既定値は null です。

属性

次のコード例では、 コントロールで TreeViewXmlDataSource使用して、変換された XML データを表示する方法を示します。 XML 変換は、 プロパティで示されるスタイル シートを TransformFile 使用して実行されます。 さらに、スタイル シートでは、実行時に オブジェクトのデータ ソース コントロールに渡される変換引数を XsltArgumentList 使用します。 コード例では、カスタム イベント ハンドラーを XsltArgumentList 使用して イベントを処理して、 をデータ ソース コントロールに Transforming 渡す方法を示します。

<%@ 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 ファイルには、次のデータがあります。

<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 データの変換は、次のスタイル シートを使用して実行されます。

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

注釈

XSLT 変換が TransformArgumentList XML データに適用されるときに XSLT パラメーターを使用できるように、イベントが発生したときに Transforming プロパティを設定します。

プロパティが EnableCachingtrue 設定されていて、 TransformArgumentList プロパティが設定されている場合、transforms 引数リストでパラメーターが変更されても、キャッシュ エントリは自動的に無効になりません。 その場合は、 プロパティを設定してキャッシュを無効にするコードを記述する CacheKeyDependency 必要があります。

適用対象

こちらもご覧ください