XSLT 2.0 for .NETYou don't have to wait to use XSLT 2.0 with .NET. Altova AltovaXML® 2012 Community Edition is a royalty-free XML standards processor that includes the Altova XSLT 1.0 and XSLT 2.0 processors, XQuery processor, XBRL validator, and XML validator for developers to use in their own applications for free. .NET developers in particular will find this free XSLT 2.0 processor invaluable for implementing solutions that take full advantange of the power of the 2.0 version of the XSLT language. Through AltovaXML, Altova makes the same XSLT 2.0 engine included in its award-winning XMLSpy, MapForce, and StyleVision XML development tools available in a convenient executable. That means you can use the very engines that have helped make Altova software the industry’s leading XML development toolset – and the choice of over 4 million users – in the .NET environment! AltovaXML® 2012 provides full support for XSLT 2.0 and includes a.NET interface, allowing you easy access to the benefits of XSLT 2.0 directly in the .NET environment. Download and Installation
After you have downloaded the installer file to your machine, double-click it to start the installation. The installer will install AltovaXML in the Altova/AltovaXML2011 folder in the Program Files folder. All the necessary registrations to use AltovaXML via a COM interface and in the .NET environment will be done by the installer (using AltovaXML from Java is also supported). This includes registering the AltovaXML executable as a COM server object and adding the Altova.AltovaXML.dll file to the .NET reference library. The .NET interface is built as a wrapper around the AltovaXML COM interface. It is provided as a primary interop assembly signed by Altova and using the namespace Altova.AltovaXML. In order to use AltovaXML in your .NET project, you need to: (i) have AltovaXML registered as a COM server object (which is done by the installer), and (ii) add a reference to the Altova.AltovaXML assembly to your project. Once these requirements have been met, you can use the AltovaXML functionality in your project.
Using XSLT 2.0 for .NETThe Altova.AltovaXML.XSLT2 object provides methods and properties to execute an XSLT 2.0 transformation using the Altova XSLT 2.0 Engine. Results can be saved to a file or returned as a string. The object also enables XSLT parameters to be passed to the XSLT stylesheet. The URLs of XML and XSLT files can be supplied as strings via the object's properties. Alternatively, the XML and XSLT documents can be constructed within the code as text strings. The following example C# code calls an XML to XML transformation via XSLT 2 in .NET:
// Specify folder (AltovaXMLExamples folder)
// Check if filepath is correct for you
String strExamplesFolder = Environment.GetEnvironmentVariable("ProgramFiles") +
"\\Altova\\AltovaXML2011\\AltovaXMLExamples\\";
// Create a new AltovaXML instance and access its engines
Altova.AltovaXML.Application AltovaXML = new Altova.AltovaXML.Application();
// Use XSLT2 Engine of AltovaXML to transform simple.xml using CopyInputXSLT2.xsl
Altova.AltovaXML.IXSLT2 AltovaXMLXSLT2 = AltovaXML.XSLT2;
AltovaXMLXSLT2.InputXMLFileName = strExamplesFolder + "simple.xml";
AltovaXMLXSLT2.XSLFileName = strExamplesFolder + "CopyInputXSLT2.xsl";
AltovaXMLXSLT2.Execute(strExamplesFolder + "simpleOutputFromXML.xml");
Here is an example of C# code initiating an XSLT 2.0 string-to-string transformation with AltovaXML:
// Specify folder (AltovaXMLExamples folder)
// Check if filepath is correct for you
String strExamplesFolder = Environment.GetEnvironmentVariable("ProgramFiles") +
"\\Altova\\AltovaXML2011\\AltovaXMLExamples\\";
// Create a new AltovaXML instance and access its engines
Altova.AltovaXML.Application AltovaXML = new Altova.AltovaXML.Application();
// Use XSLT2 Engine of AltovaXML to transform input string using CopyInputXSLT2.xsl
Altova.AltovaXML.IXSLT2 AltovaXMLXSLT2 = AltovaXML.XSLT2;
AltovaXMLXSLT2.InputXMLFromText = "<;?xml version='1.0'?><doc>Hello World</doc>";
AltovaXMLXSLT2.XSLFileName = strExamplesFolder + "CopyInputXSLT2.xsl";
String strResult = AltovaXMLXSLT2.ExecuteAndGetResultAsString();
// Show result
MessageBox.Show("XSLT 2.0 engine answered: " + strResult);
Using .NET Extensions with XSLT 2.0 TransformationsSee the C# code examples below for using .NET extensions with the AltovaXML XSLT 2.0 engine.
// Specify folder (AltovaXMLExamples folder)
// Check if filepath is correct for you
String strExamplesFolder = Environment.GetEnvironmentVariable("ProgramFiles") +
"\\Altova\\AltovaXML2011\\AltovaXMLExamples\\";
// Create a new AltovaXML instance and access its engines
Altova.AltovaXML.Application AltovaXML = new Altova.AltovaXML.Application();
// Use XSLT2 Engine from AltovaXML application
Altova.AltovaXML.IXSLT2 AltovaXMLXSLT2 = AltovaXML.XSLT2;
// Enable .NET extensions
AltovaXMLXSLT2.DotNetExtensionsEnabled = 1;
// Use XSLT containing .NET math extension for transformation
AltovaXMLXSLT2.InputXMLFileName = strExamplesFolder + "simple.xml";
AltovaXMLXSLT2.XSLFromText = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:math='clitype:System.Math' version='2.0'><xsl:output omit-xml-declaration='yes'/>
<xsl:template match='/'><a><sqrtanswer><xsl:value-of select='math:Sqrt(9)'/></sqrtanswer></a>
</xsl:template></xsl:stylesheet>";
AltovaXMLXSLT2.Execute(strExamplesFolder + "Output.xml");
// Release ALL references to all components that were received.
System.Runtime.InteropServices.Marshal.ReleaseComObject(AltovaXMLXSLT2);
AltovaXMLXSLT2 = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(AltovaXML);
AltovaXML = null;
AltovaXML DocumentationFor more examples and complete information about using AltovaXML® 2012 in your own applications, please refer to the developer documentation. |
| ||||||||||||||||||||||||||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
