XSLT and Open XML

Download Report

Transcript XSLT and Open XML

XSLT and Open XML
Open XML Developer Workshop
Disclaimer
The information contained in this slide deck represents the current view of Microsoft Corporation on the issues discussed as of the date of
publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the
part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.
This slide deck is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE
INFORMATION IN THIS DOCUMENT.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this slide
deck may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic,
mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft
Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this
slide deck. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this slide deck does not give
you any license to these patents, trademarks, copyrights, or other intellectual property.
Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events
depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo,
person, place or event is intended or should be inferred.
© 2006 Microsoft Corporation. All rights reserved.
Microsoft, 2007 Microsoft Office System, .NET Framework 3.0, Visual Studio, and Windows Vista are either registered trademarks or
trademarks of Microsoft Corporation in the United States and/or other countries.
The names of actual companies and products mentioned herein may be the trademarks of their respective owners.
Open XML Developer Workshop
Overview
Working with XSLT in .NET
XSLT Business Scenarios
Open XML Developer Workshop
Lesson: Working with XSLT in .NET
XSLT Architecture in the .NET Framework
Rich Features of the XSLT Infrastructure
Passing Values to the XSLT Transformation
Working with Extension Objects
Pointers on Open XML Transformations
Open XML Developer Workshop
XSLT Architecture in the .NET Framework
XmlDocument
XPathDocument
XPathNavigator
Url
XmlReader
XslCompiledTransform.Load()
XSLT
XmlDocument
XPathDocument
XPathNavigator
File
XslCompiledTransform.Transform()
Open XML Developer Workshop
XmReader
XmlWriter
TextWriter
Stream
Url
Rich Features of the XSLT Infrastructure
Pass .NET values to the XSLT engine using the
XsltArgumentList.AddParam() method
Call .NET methods from inside the XSLT using Extension
Objects
Available through the XsltArgumentList.AddExtensionObject()
method
Render XSLT results out on the web using the ASP.NET
XmlControl
Open XML Developer Workshop
Passing Values to the XSLT Transformation
XSLT style sheets can receive parameters
<xsl:param name=“discount" />
...
<xsl:value-of select=“@price – (@price * $discount)"/>
String
Boolean
Double
XPathNavigator
XPathNodeIterator
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load("sample.xslt");
XsltArgumentList arguments = new XsltArgumentList();
arguments.AddParam(“discount", "", 0.30);
using (FileStream fs = new FileStream("output.txt"))
{
transform.Transform(document, arguments, fs);
}
Open XML Developer Workshop
Working with Extension Objects
An extension object is a .NET object referenced from
inside the style sheet.
Each method is exposed as a custom function
class MyClass
{
public string MyMethod(
int value) {
…
}
}
<xsl:stylesheet …
xmlns:myNs=“urn:myUrn”>
<xsl:value-of
select=“myNs:MyMethod(123)” />
</xsl:stylesheet>
Open XML Developer Workshop
Pointers on Open XML Transformations
When transforming from Open XML
Access other document parts with the XSLT document() function
<xsl:for-each select="document(other.xml)/my/element">
Resolve paths to external resources using a custom
XmlResolver class
class SampleResolver
: XmlResolver
{
Package _package;
public override object GetEntity(Uri absoluteUri,
string role, Type ofObjectToReturn)
{
PackagePart part = _package.GetPart(absoluteUri);
return part.GetStream();
}
}
Open XML Developer Workshop
Lesson: XSLT Business Scenarios
Custom Data to Open XML
Open XML to ODF
WordprocessingML to XSL-FO
WordprocessingML to HTML
Open XML Developer Workshop
ODF
XSL-FO
RTF
PDF
HTML
XPS
Open XML
SQL
XML
Open XML Developer Workshop
ODF
Review
Working with XSLT in .NET
XSLT Business Scenarios
Open XML Developer Workshop
Open XML Developer Workshop