Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
868
|
Chapter 15: XML
See Also
See Recipe 15.4 and the “XmlDocument.Validate” topic in the MSDN documenta-
tion.
15.12 Extending XSLT Transformations
Problem
You want to perform operations that are outside the scope of XSLT to include data
in the transformed result.
Solution
Add an extension object to the transformation that can perform the operations nec-
essary based on the node it is passed. This can be accomplished by using the
XsltArgumentList.AddExtensionObject method. This object you’ve created (XslExtensionObject)
can then be accessed in the XSLT and a method called on it to return the data you
want included in the final transformed result:
string xmlFile = @"..\..\publications.xml";
string xslt = @"..\..\publications.xsl";
//Create the XslTransform and load the stylesheet.
// This is not XslCompiledTransform because it gives a different empty node.
//Create the XslCompiledTransform and load the stylesheet.
XslCompiledTransform transform = new XslCompiledTransform( );
transform.Load(xslt);
// Load the XML.
XPathDocument xPathDoc = new XPathDocument(xmlFile);
// Make up the args for the stylesheet with the extension object.
XsltArgumentList xslArg = new XsltArgumentList( );
// Create our custom extension object.
XSLExtensionObject xslExt = new XSLExtensionObject( );
xslArg.AddExtensionObject("urn:xslext", ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata