XsltArgumentList.AddExtensionObject メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XsltArgumentList.AddExtensionObject メソッドの意味・解説 

XsltArgumentList.AddExtensionObject メソッド

新しオブジェクトを XsltArgumentList に追加し、それを名前空間 URI関連付けます。

名前空間: System.Xml.Xsl
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Sub AddExtensionObject ( _
    namespaceUri As String, _
    extension As Object _
)
Dim instance As XsltArgumentList
Dim namespaceUri As String
Dim extension As Object

instance.AddExtensionObject(namespaceUri, extension)
public void AddExtensionObject (
    string namespaceUri,
    Object extension
)
public:
void AddExtensionObject (
    String^ namespaceUri, 
    Object^ extension
)
public void AddExtensionObject (
    String namespaceUri, 
    Object extension
)
public function AddExtensionObject (
    namespaceUri : String, 
    extension : Object
)

パラメータ

namespaceUri

オブジェクト関連付ける名前空間 URI既定名前空間使用するには、空の文字列指定します

extension

リスト追加するオブジェクト

例外例外
例外種類条件

ArgumentException

namespaceUrinull 参照 (Visual Basic では Nothing) または http://www.w3.org/1999/XSL/Transform です。

namespaceUri には、既に拡張オブジェクト関連付けられています。

SecurityException

呼び出し元に、このメソッド呼び出すための十分なアクセス許可がありません。

解説解説

渡すことができるパラメータの数に制限のない params キーワードは、現在サポートされていません。この params キーワードを使用して定義されるメソッド利用する XSLT スタイルシート正しく動作しません。詳細については、「params (C# リファレンス)」を参照してください

呼び出し時の注意 FullTrust は、このメソッド呼び出す必要があります詳細については、「コード アクセス セキュリティ」を参照してください

使用例使用例

スタイル シートXSLT 拡張オブジェクト使用し書籍価格変換する例を次に示します

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl

Public Class Sample
        
    Public Shared Sub Main()
 
        
        ' Create the XslCompiledTransform and load the stylesheet.
        Dim xslt As New
 XslCompiledTransform()
        xslt.Load("prices.xsl")
        
        ' Load the XML data file.
        Dim doc As New XPathDocument("books.xml")
        
        ' Create an XsltArgumentList.
        Dim xslArg As New
 XsltArgumentList()
        
        ' Add an object to calculate the new book price.
        Dim obj As New BookPrice()
        xslArg.AddExtensionObject("urn:price-conv",
 obj)
        
        ' Transform the file.
        xslt.Transform("books.xml", xslArg, XmlWriter.Create("output.xml"))
    
    End Sub 'Main 
    
    ' Convert the book price to a new price using the conversion factor.
    
    Public Class BookPrice
        
        Private newprice As Decimal
 = 0
                
        Public Function NewPriceFunc(ByVal
 price As Decimal, ByVal
 conv As Decimal) As Decimal 
            Dim tmp As Decimal
 = price * conv
            newprice = Decimal.Round(tmp, 2)
            Return newprice        
        End Function 'NewPriceFunc

    End Class 'BookPrice

End Class 'Sample
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public class Sample {

   public static void Main()
 {

    // Create the XslCompiledTransform and load the stylesheet.
    XslCompiledTransform xslt = new XslCompiledTransform();
    xslt.Load("prices.xsl");

    // Load the XML data file.
    XPathDocument doc = new XPathDocument("books.xml");

    // Create an XsltArgumentList.
    XsltArgumentList xslArg = new XsltArgumentList();
         
    // Add an object to calculate the new book price.
    BookPrice obj = new BookPrice();
    xslArg.AddExtensionObject("urn:price-conv", obj);

    // Transform the file.
    xslt.Transform("books.xml", xslArg, XmlWriter.Create("output.xml"));

  }

  // Convert the book price to a new price using the conversion factor.
  public class BookPrice{

    private decimal newprice = 0;
        
    public decimal NewPriceFunc(decimal price, decimal conv){
       decimal tmp = price*conv;
       newprice = decimal.Round(tmp, 2);
       return newprice;
    }
  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::XPath;
using namespace System::Xml::Xsl;

// Convert the book price to a new price using the conversion factor.
public ref class BookPrice
{
private:
   Decimal newprice;

public:
   BookPrice()
   {
      newprice = 0;
   }

   Decimal NewPriceFunc( Decimal price, Decimal conv )
   {
      Decimal tmp = price * conv;
      newprice = Decimal::Round( tmp, 2 );
      return newprice;
   }

};

public ref class Sample
{

public:
   Sample()
   {
      
      // Create the XslCompiledTransform and load the stylesheet.
      XslCompiledTransform^ xslt = gcnew XslCompiledTransform;
      xslt->Load( "prices.xsl" );
      
      // Load the XML data file.
      XPathDocument^ doc = gcnew XPathDocument( "books.xml" );
      
      // Create an XsltArgumentList.
      XsltArgumentList^ xslArg = gcnew XsltArgumentList;
      
      // Add an object to convert the book price.
      BookPrice^ obj = gcnew BookPrice;
      xslArg->AddExtensionObject( "urn:price-conv", obj );
            
      // Transform the file.
      xslt->Transform(doc, xslArg, XmlWriter::Create("output.xml"));

   }

};

int main()
{
   Sample^ test = gcnew Sample;
}

import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.XPath.*;
import System.Xml.Xsl.*;

public class Sample
{

    public static void main(String[]
 args)
    {
        Sample test = new Sample();
    } //main

    public Sample()
    {
        // Create the XslCompiledTransform and load the stylesheet.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load("prices.xsl");

        // Load the XML data file.
        XPathDocument doc = new XPathDocument("books.xml");

        // Create an XsltArgumentList.
        XsltArgumentList xslArg = new XsltArgumentList();

        // Add an object to convert the book price.
        BookPrice obj = new BookPrice();
        xslArg.AddExtensionObject("urn:price-conv", obj);

        // Transform the file.
        xslt.Transform("books.xml", xslArg, XmlWriter.Create("output.xml"));
        
    } // Sample

    // Convert the book price to a new price using the conversion factor.
    public class BookPrice
    {
        private System.Decimal newprice = System.Convert.ToDecimal(0);

        public System.Decimal NewPriceFunc(System.Decimal price
,
            System.Decimal conv)
        {
            System.Decimal tmp = Decimal.Multiply(price, conv);
            newprice = System.Decimal.Round(tmp, 2);
            return newprice;
        } //NewPriceFunc
    } //BookPrice
} //Sample

この例では、次のデータ ファイル入力として使用してます。

books.xml

<bookstore>
  <book genre="autobiography"
 publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography
 of Benjamin Franklin</title>
    <author>
      <first-name>Benjamin</first-name>
      <last-name>Franklin</last-name>
    </author>
    <price>8.99</price>
  </book>
  <book genre="novel" publicationdate="1967"
 ISBN="0-201-63361-2">
    <title>The Confidence
 Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.99</price>
  </book>
  <book genre="philosophy" publicationdate="1991"
 ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

prices.xsl

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myObj="urn:price-conv">

<!--Price conversion factor-->
<xsl:param name="conv" select="1.15"/>

  <xsl:template match="bookstore">
  <bookstore>
  <xsl:for-each select="book">
    <book>
    <xsl:copy-of select="node()"/>
       <new-price>
          <xsl:value-of select="myObj:NewPriceFunc(./price,
 $conv)"/>        
       </new-price>
    </book>
  </xsl:for-each>
  </bookstore>
  </xsl:template>
</xsl:stylesheet>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からXsltArgumentList.AddExtensionObject メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXsltArgumentList.AddExtensionObject メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXsltArgumentList.AddExtensionObject メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XsltArgumentList.AddExtensionObject メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XsltArgumentList.AddExtensionObject メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS