Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Linq to XSLT

Is there a way to convert LINQ queries into XSLT? the same way LINQ can be converted to SQL?

I mean if i have a solid well defined XML(Conforms to an XSD) is there a way to compile the stuff under System.Linq.Expressions into XSLT in regard to that XML?

Thank you.

To Dimitries request I'll try to elaborate a little... Basically I have some data in one place (it's basically to chunks of xml serializable data), and I need to process them, I need to combine and process them.

Both the incoming original data , and the output result data, are XML serializable, and conform to a well defined XSD.

I want to generate the processing logic dynamically - someplace else. And allow my user to change and play around with the processing. I can represent the processing it self easily with Expression trees. Expression trees are similar to parse trees and can capture program code. This is the way linq to SQL works it converts expression trees to SQL queries.

Since all the income data and the output are both a well defined XML I can do the transformation easily with XSLT, but I'm not familiar with XSLT enough to write a dynamic XSLT generator. So I thought I could build the transformations in C# and convert them into XSLT.... again its not general purpose C#, but probably specific queries over a well defined data provider.

For the example sake:

(Not real code)

var schemas = XSchemaSet.Load("a","b");
var doc = XDocument.Load("File",schemas);

var result = from node in doc.Nodes
             where node.Name == "Cats" || node.Name == "Dogs"
             select (new Node(){Name = "Animal Owner", Value = node.Owner)
var newDoc = new XDocument().AddNodes(result);
newDoc.Validate(schemas);

Basically I want something that will function like that... I can write that in a single linq query if I use IQueryable.Aggregate

like image 600
AK_ Avatar asked Aug 03 '11 12:08

AK_


1 Answers

Yes, you can implement your own query provider, which uses XSLT internally, if you can figure out how to query with XSLT.

like image 188
George Polevoy Avatar answered Sep 20 '22 06:09

George Polevoy