XsltMessageEncounteredEventArgs Class (System.Xml.Xsl)

Switch View :
ScriptFree
.NET Framework Class Library
XsltMessageEncounteredEventArgs Class

Provides data for the XsltMessageEncountered event.

Inheritance Hierarchy

System.Object
  System.EventArgs
    System.Xml.Xsl.XsltMessageEncounteredEventArgs

Namespace:  System.Xml.Xsl
Assembly:  System.Xml (in System.Xml.dll)
Syntax

Visual Basic
Public MustInherit Class XsltMessageEncounteredEventArgs _
	Inherits EventArgs
C#
public abstract class XsltMessageEncounteredEventArgs : EventArgs
Visual C++
public ref class XsltMessageEncounteredEventArgs abstract : public EventArgs
F#
[<AbstractClass>]
type XsltMessageEncounteredEventArgs =  
    class
        inherit EventArgs
    end

The XsltMessageEncounteredEventArgs type exposes the following members.

Constructors

  Name Description
Protected method XsltMessageEncounteredEventArgs Initializes a new instance of the XsltMessageEncounteredEventArgs class.
Top
Properties

  Name Description
Public property Message Gets the contents of the xsl:message element.
Top
Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
Remarks

The XsltMessageEncountered event occurs during XSLT processing when an xsl:message is specified in the style sheet.

Note Note

If the terminate attribute is set to "yes", the XSLT processor stops executing the style sheet stops after the message is processed.

Examples

The following example uses the XsltMessageEncounteredEventArgs to display xsl:message content to the console. The sample writes the following message to the console: Message received: Author name is not in the correct format <author><name>Plato</name></author>.

Visual Basic

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

Public Class Sample    

  Public Shared Sub Main() 

    ' Create the XslCompiledTransform object and load the style sheet.
    Dim xslt As New XslCompiledTransform()
    xslt.Load("message.xsl")

    Dim argList As New XsltArgumentList()
    AddHandler argList.XsltMessageEncountered, AddressOf MessageCallBack

    ' Load the file to transform.
    Dim doc As New XPathDocument("books.xml")

    ' Transform the file.
    xslt.Transform(doc, argList, XmlWriter.Create("output.xml"))

  End Sub 'Main     

  Private Shared Sub MessageCallBack(ByVal sender As Object, ByVal e As XsltMessageEncounteredEventArgs) 
    Console.WriteLine("Message received: {0}", e.Message)

  End Sub 'MessageCallBack
End Class 'Sample 


C#

using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class Sample {

  public static void Main() {

    // Create the XslCompiledTransform object and load the style sheet.
    XslCompiledTransform xslt = new XslCompiledTransform();
    xslt.Load("message.xsl");

    XsltArgumentList argList = new XsltArgumentList();
    argList.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);
	
    // Load the file to transform.
    XPathDocument doc = new XPathDocument("books.xml");

    // Transform the file.
    xslt.Transform(doc, argList, XmlWriter.Create("output.xml"));

  }

  private static void MessageCallBack(object sender, XsltMessageEncounteredEventArgs e) {
    Console.WriteLine("Message received: {0}", e.Message);
  }

}


The example uses the following files as input:

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>


message.xsl


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:template match="/">
     <xsl:apply-templates select="*"/>
     <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="*">
     <xsl:apply-templates select="//author"/>
  </xsl:template>

  <xsl:template match="author">
    <xsl:if test="not (last-name)">
       <xsl:message terminate="no">Author name is not in the correct format <xsl:copy-of select="."/>
       </xsl:message>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference