LeonM
LeonM

Reputation: 13

Use XSLT stylesheet with XML in ASP.NET MVC3

I am currently working on a small side-project in MVC3. The goal is to make a personalized schedule (school). When users login, they should be able to review their schedule.

The XML with data is already delivered by an other programmer. A sample XML is found here http://hrooster.leonmastenbroek.nl/student-current.xml

I've managed to deserialize the XML to an object by creating a class with the "xsd.exe" tool. But honestly I don't know if that is useful :)

Now comes the question: How do you parse a XML file/object with a stylesheet (XSLT) into a Razor template? As you can see there are a lot of attributes in the timetable node so there are a lot of references. I made a stylesheet to arrange the data properly, but I don't have a clue how to combine it together.

Also it should be nested in a jQuery Mobile content div. And the XML is delivered by URL to me.

Upvotes: 1

Views: 1215

Answers (1)

MDev
MDev

Reputation: 46

There are several different ways. If you the .NET Framework using Linq to XML to parse the XML into objects then XSLT is not really needed as you have already transformed the XML.

You can just transform the XML so that it created something like the following,

<description>@item.Description</description>

the @ is the prefix to the variable names.

If I was using XSLT I would be looking to create an HTML file of the data, I would then just output the HTML using Razor.

This may help,

How to apply an XSLT Stylesheet in C#

Upvotes: 1

Related Questions