How to: Use C # .NET to apply XSL Conversion (from MSDN)

xiaoxiao2021-03-06  76

The release number of this article has been CHS307322

This article discusses a Beta version of Microsoft products. The information in this article is provided as "as", if there is any change without notice.

For this Beta product, Microsoft does not provide formal product support. For information on gain support for Beta versions, see the documentation included in the beta product file or view the site you downloaded.

For Microsoft Visual Basic .NET versions of this article, see

300929.

This task content

Summary

The step of the step of generating this example is required.

Summary How to use this article

XSLTransform class Apply Extensible Style Sheet Language (XSL) Conversion (XSLT) to the Scalable Markup Language (XML) document to create a new XML document. XSL is an XML-based language that converts an XML document to another XML document, or converts an XML document to any other structure.

Back to top

The following table summarizes the recommended hardware, software, network architecture, and service pack required:

Microsoft Visual Studio .NET Microsoft .NET SDK Quick Start This article is assumed to be familiar with the following topics:

XML Terminology Create and Read XML File XML Path Language (XPath) Syntax XSL

Back to top

Steps to generate an example This example uses two files named BOOKS.XML and BOOKS.XSL. You can create your own books.xml and books.xsl files, or use the sample file included in the .NET Software Development Kit (SDK). Books.xml and books.xsl files must be copied into the / bin / debug folder, which is located below the folder where this item is created. These files can be found in the following folders:

../Program files / microsoft visual studio .NET / FRAMEWORKSDK / SAMPLES / QuickStart / HOWTO / SAMPLES / XML / Transformxml / CS

Create a C # console application in Visual Studio .NET. Make sure the project contains references to System.xml namespaces, if not, add this reference. Use the USING statement for XML and XSL namespace, so that there is no need to limit the declarations in these namespaces in the following code. The USING statement must be before all other declarations. USING SYSTEM.XML;

Using system.xml.xsl; declare the corresponding variable and an XSLTransform object to convert the XML document. Xsltransform myxsltransform; constructs a new XslTransform object. The XSLTransform class is an XSLT processor that implements the XSLT version 1.0. MyXSLTRANSFORM = New xsltransform (); loads the xsltransform object with this style using the LOAD method. This style sheet converts the specific contents of the books.xsl file into a list of simple ISBN books. MYXSLTRANSFORM.LOAD ("Books.xsl") calls the Transform method to initiate the conversion process, and pass the XML source document and the converted XML document name to the method. MyXSLTransform.Transform ("Books.xml", "isbnbookList.xml"; generates and runs your project. The generated ISBNBookList.xml file can be found in the / bin / debug folder under the folder where the project file is located.

Back to top

Complete code example

Using system; using system.xml;

Using system.xml.xsl;

Namespace XSLTransformation

{

///

/// summary description for class1.

///

Class class1

{

Static void main (string [] args)

{

Xsltransform myxsltransform;

Myxsltransform = new xsltransform ();

MYXSLTRANSFORM.LOAD ("Books.xsl");

MYXSLTRANSFORM.TRANSFORM ("Books.xml", "ISBNBookList.xml";

}

}

}

Back to top

Reference

For more information on the XSLTransform class, see the following Microsoft .NET Framework Class library documentation:

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlxslxsltransformClasstopic.asp?frame=true

XSLTransform class with

For more information on the XSLTransform object, see the following Microsoft .NET Framework Developer's Guide document:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpconxsltransformclassimplementsxsltprocessor.asp?frame=true information about XSLT and actual comparison Active Server Pages .NET, please See the following

MSDN Online Voices Extreme XML Sea:

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexxml/html/xml02192001.asp For more information on .NET XML, see "XML IN .NET: .NET Framework XML classes and C # Offer Simple, Scalable Data Manipulation "(. NET XML: .NET Framework XML class and C # provide simple, scalable data operations), this article is

In MSDN Magazine, you can access from the following Microsoft Web site:

http://msdn.microsoft.com/msdnmag/issues/01/01/xml/xml.asp

Back to top

The information in this article applies to:

Microsoft Visual C # .NET Beta 2

Recent Updated: 2001-11-5 (1.0) Keyword Kbhowto KbhowTomaster KB307322 KBAUDDEVELOPER

转载请注明原文地址:https://www.9cbs.com/read-109018.html

New Post(0)