<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx</link><description>[Blog Map] You can use LINQ to XML to transform XML trees with the same level of power and expressability as with XSLT, and in many cases more than with XSLT. One of the reasons that XSL is so powerful is that you can write multiple rules to transform</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>A E  &amp;raquo; Blog Archive   &amp;raquo; Using Annotations to Transform LINQ to XML Trees in an XSLT Style&amp;#8230;</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8644103</link><pubDate>Tue, 24 Jun 2008 01:48:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8644103</guid><dc:creator>A E  &amp;raquo; Blog Archive   &amp;raquo; Using Annotations to Transform LINQ to XML Trees in an XSLT Style&amp;#8230;</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://ae.morelyrics.co.uk/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style/"&gt;http://ae.morelyrics.co.uk/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8644390</link><pubDate>Tue, 24 Jun 2008 03:05:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8644390</guid><dc:creator>Oran</dc:creator><description>&lt;p&gt;Very cool! &amp;nbsp;Do you have performance metrics comparing this technique to XSLT?&lt;/p&gt;
&lt;p&gt;It would be so cool if you could talk the BizTalk team into making the BizTalk mapper output this instead of XSLT.&lt;/p&gt;
</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8644466</link><pubDate>Tue, 24 Jun 2008 03:29:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8644466</guid><dc:creator>EricWhite</dc:creator><description>&lt;p&gt;I don't yet have performance metrics. &amp;nbsp;There is an open source XSL that does a fairly comprehensive transform of an Open XML document to html. &amp;nbsp;I'd really like my DocxToHtml.cs to be as comprehensive as the XSL version. &amp;nbsp;At that point, it would be fair to compare the performance of the two.&lt;/p&gt;
&lt;p&gt;Right now, the only transforms that I have are the trivial ones presented in this post, as I just wrote this code over the weekend. &amp;nbsp;It wouldn't really be meaningful to define the same transformations in XSL and compare perf - an XSL transform must fire up the XSL transformation engine, which is a fixed perf cost for every transform.&lt;/p&gt;
&lt;p&gt;As I improve the DocxToHtml transform, I'll certainly post the improved code. &amp;nbsp;And when it is comprehensive enough, we'll get numbers.&lt;/p&gt;
&lt;p&gt;I'm going to make a bet, however, that this code will perform very well when compared with XSLT.&lt;/p&gt;
</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8649047</link><pubDate>Wed, 25 Jun 2008 00:00:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8649047</guid><dc:creator>Sal Mangano</dc:creator><description>&lt;p&gt;XSLT has a lot of very important ideas that are locked up in an unfortunate syntax. Any effort to extract these ideas into a cleaner environment is a good one. However, I see nothing in your demonstration that convinces me you have accomplished this and certainly nothing to suggest:&lt;/p&gt;
&lt;p&gt;&amp;quot;LINQ to XML to transform XML trees with the same level of power and expressability as with XSLT, and in many cases more than with XSLT.&amp;quot;&lt;/p&gt;
&lt;p&gt;Can you elaborate how this has the more power and expressability than XSLT?&lt;/p&gt;
</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8649217</link><pubDate>Wed, 25 Jun 2008 00:44:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8649217</guid><dc:creator>EricWhite</dc:creator><description>&lt;p&gt;Hi Sal,&lt;/p&gt;
&lt;p&gt;Yes, XSLT is very powerful, and has many important ideas in an unfortunate syntax. &amp;nbsp;To me, the most important ideas are:&lt;/p&gt;
&lt;p&gt;- pattern matching / application of templates&lt;/p&gt;
&lt;p&gt;- ability to specify a transformation for a node, while applying further transformations deeper in the tree&lt;/p&gt;
&lt;p&gt;- when used properly, a pure, stateless functional approach&lt;/p&gt;
&lt;p&gt;Using this approach, LINQ also can use pattern matching to select nodes to transform, and ability to specify transformations for any node, while applying further transformations deeper in the tree. &amp;nbsp;And of course, with lambda expressions, extension methods, deep support for generics, etc., LINQ/C# 3.0 syntax certainly supports a natural syntax for a pure functional approach. &amp;nbsp;I personally find the syntax of LINQ, and of LINQ to XML easier to read and write than XSLT, hence the expressability. &amp;nbsp;I also consider the much richer type system in C# to be something that also adds to the power and expressability.&lt;/p&gt;
&lt;p&gt;With regards to power, the last example presented in this post includes referencing data that is contained in some C# objects. &amp;nbsp;If attempting this transform with XSLT, you must first serialize this data into XML and then use the XML in a transformation, or you must escape into an external language to retrieve the data. &amp;nbsp;Using LINQ to XML, you can write one single, pure, functional transformation that can use data from anywhere in the .NET stack. &amp;nbsp;You could write a pure, functional transformation that uses data from a database, the file system, XML of course, JSON, web services, etc., etc.&lt;/p&gt;
&lt;p&gt;There are downsides to using LINQ - the language doesn't enforce a pure functional approach. &amp;nbsp;You can easily break purity by mutating variables, etc. &amp;nbsp;In contrast, with XSLT, you have try hard to write impure code.&lt;/p&gt;
&lt;p&gt;What has been missing in the C# 3.0 / LINQ conversation is a technique for expressing the pattern matching / templates approach. &amp;nbsp;This post describes my approach for doing this.&lt;/p&gt;
&lt;p&gt;-Eric&lt;/p&gt;
</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8649931</link><pubDate>Wed, 25 Jun 2008 03:54:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8649931</guid><dc:creator>Sal Mangano</dc:creator><description>&lt;p&gt;I think the features of XSLT you reference are imporant but what makes an XSLT solution more powerful in the domain of XML -&amp;gt; XML transforms are &amp;quot;Literal Result Elements&amp;quot; which are cleaner syntactically than &amp;quot;new XElement(...)&amp;quot;. XSLT 2.0 also has a much richer facility for specializing templates then you imply in your post (multiple modes, xsl:next-match, xsl:import, named templates, priorities, etc.) Also, using a subset of XPath as a pattern language is very powerful. &lt;/p&gt;
&lt;p&gt;Your LINQ based approach is far too procedural for my tastes.&lt;/p&gt;
&lt;p&gt;However, outside of XML -&amp;gt; XML, XSLT starts to trip over itself.&lt;/p&gt;
</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8651148</link><pubDate>Wed, 25 Jun 2008 08:52:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8651148</guid><dc:creator>EricWhite</dc:creator><description>&lt;P&gt;I agree with you that sequence constructors have a cleaner syntax than newing up XElement objects. &amp;nbsp;And I agree that literal result elements are nice for simple transforms to XHTML. &amp;nbsp;XML literals in VB are pretty cool, except that I just happen to prefer C#. &amp;nbsp;I saw the issues that came up when introducing XML literals to VB - they were not trivial. &amp;nbsp;I prefer C# without the literals. &amp;nbsp;There is a syntactically minimalist approach to constructing LINQ to XML trees in C# - I haven't used it for some time, but it can serve to reduce syntactic noise. &amp;nbsp;I might have to play with it again, and see if it helps. &amp;nbsp;I personally don't mind using XElement/XAttribute constructors. &amp;nbsp;But this is a good point.&lt;/P&gt;
&lt;P&gt;xsl:include and xsl:import are examples of composability, and C# 3.0 used in a functional style takes composability to a high level.&lt;/P&gt;
&lt;P&gt;Multiple modes are handled in C# with a dictionary. &amp;nbsp;The implementation is trivial - no modifications to this little library is needed. &amp;nbsp;Same with priorities - add tuples to a dictionary, select ordered results using LINQ expressions.&amp;nbsp; I'd have to write out the code to show you exactly what I mean.&amp;nbsp; But would be another blog post.&lt;/P&gt;
&lt;P&gt;Regarding XPath vs LINQ query expressions, have to tell you, I've written more of both than I care to count. &amp;nbsp;I prefer LINQ. &amp;nbsp;Others might prefer XPath.&lt;/P&gt;
&lt;P&gt;Actually, there is very little procedural code in these examples. &amp;nbsp;Basically, the transform doesn't care what order you add the annotations, unless you are adding the annotations in a specific order so that certain of the transformations take precedence over the others. &amp;nbsp;When you refer to procedural code, what are you referring to? &amp;nbsp;(Note: not being sarchastic or anything - too much is lost in written communication -&amp;nbsp;I'm just asking because&amp;nbsp;I'm curious about what you see. &amp;nbsp;:-)&lt;/P&gt;
&lt;P&gt;BTW, there is another way to write the foreach loops - write them using an extension method public void ForEach&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt;source, Action&amp;lt;T&amp;gt; action) ...&lt;/P&gt;
&lt;P&gt;I changed the code to use foreach, because it is more accessible, and less strange to many developers new to FP.&lt;/P&gt;</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8663143</link><pubDate>Sat, 28 Jun 2008 04:29:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8663143</guid><dc:creator>EricWhite</dc:creator><description>&lt;P&gt;Sal,&lt;/P&gt;
&lt;P&gt;This conversation has really provoked thought about how to specify these types of transformations in a more declarative way. &amp;nbsp;This conversation has been very valuable to me, it has made me see this from another perspective. &amp;nbsp;One thing that wasn't clear - I see the foreach iterations as just another form of a function call, maybe more accessible to some developers. &amp;nbsp;So the specification becomes a collection of calls to functions, where each call does annotation of the source tree.&amp;nbsp;&amp;nbsp;So in my mind, I hadn't deviated from a pure, functional transform. &amp;nbsp;However, the code LOOKS much more procedural. &amp;nbsp;Rewriting the transforms using the ForEach extension method helps make it look less procedural. &amp;nbsp; But there are ways to make the transformation specification even more declarative. &amp;nbsp;I'm currently working on another iteration of the approach. &amp;nbsp;Should be posted sometime in the next little while.&lt;/P&gt;
&lt;P&gt;My only motivation here is think about new ways to do transformation, not to promote one technology over another.&lt;/P&gt;
&lt;P&gt;I just have to say, there are scenarios where XSLT is a fantastic technology, and probably the only feasible technology. &amp;nbsp;In certain scenarios, I consider XSLT as the only option. &amp;nbsp;I personally know of examples they are using primarily a natively compiled XSLT processor; nothing else performs well enough. &lt;/P&gt;
&lt;P&gt;Anyway, please don't take my ramblings as an expression of disrespect for XSLT. &amp;nbsp;It is the wonderful ideas of XSLT that I have missed when writing LINQ to XML transformations.&lt;/P&gt;
&lt;P&gt;And also, any ideas that I express are completely my own, and not Microsoft’s. &amp;nbsp;:-)&lt;/P&gt;
&lt;P&gt;-Eric&lt;/P&gt;</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8671250</link><pubDate>Mon, 30 Jun 2008 15:18:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8671250</guid><dc:creator>Vishal Doshi</dc:creator><description>&lt;p&gt;I'm pretty familiar with (and hence?) very comfortable with LINQ syntax. Not so with XSLT. I wonder if you could extend the above example to be a &amp;quot;LINQ to XML to XSLT&amp;quot; compiler?&lt;/p&gt;
&lt;p&gt;It would so cool if say, I could use LINQPad to quickly write a transform and then have that magically compiled to XSLT &amp;nbsp;(which is so much easier to release because you don't have to worry about .net 3.5 being installed etc, and will work on so many older systems etc )&lt;/p&gt;
</description></item><item><title>[Open XML] Les liens de la semaine – 27/06/08</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8671409</link><pubDate>Mon, 30 Jun 2008 16:36:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8671409</guid><dc:creator>Julien Chable</dc:creator><description>&lt;p&gt;Les quelques liens int&amp;#233;ressants de la semaine pour vos projets Open XML : Technique : Custom XML : r&amp;#233;p&amp;#233;ter&lt;/p&gt;
</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#8671451</link><pubDate>Mon, 30 Jun 2008 17:01:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8671451</guid><dc:creator>EricWhite</dc:creator><description>&lt;P&gt;Vishal,&lt;/P&gt;
&lt;P&gt;In theory, it could be possible. &amp;nbsp;The most work would be generation of XPath expressions from an expression tree. &amp;nbsp;One issue - there are LINQ expressions that have no correlating XPath expression.&lt;/P&gt;
&lt;P&gt;But it's a worthy activity to learn XSLT. &amp;nbsp;I really appreciated the book by Michael Kay.&lt;/P&gt;
&lt;P&gt;-Eric&lt;/P&gt;</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#9935241</link><pubDate>Thu, 10 Dec 2009 17:58:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9935241</guid><dc:creator>alex</dc:creator><description>&lt;p&gt;What about following&lt;/p&gt;
&lt;p&gt; - superscript subscript&lt;/p&gt;
&lt;p&gt; - Table heading alignment - top - bottom centered..&lt;/p&gt;
&lt;p&gt;Also it sometimes bolds text which is clearly not bold.&lt;/p&gt;
</description></item><item><title>re: Using Annotations to Transform LINQ to XML Trees in an XSLT Style (Improved Approach)</title><link>http://blogs.msdn.com/ericwhite/archive/2008/06/23/using-annotations-to-transform-linq-to-xml-trees-in-an-xslt-style-improved-approach.aspx#9935608</link><pubDate>Fri, 11 Dec 2009 10:36:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9935608</guid><dc:creator>Eric White</dc:creator><description>&lt;p&gt;Hey Alex, I'm currently working on a much better conversion of word-proc docs to Html. &amp;nbsp;I should be blogging on this in the next couple of weeks. &amp;nbsp;But caveat, the first version will not contain formatting, just an accurate representation of content. &amp;nbsp;I'm planning on completing the version with formatting sometime early next year.&lt;/p&gt;
&lt;p&gt;-Eric&lt;/p&gt;
</description></item></channel></rss>