This project is read-only.

Orchard and Dynamic Content with XSLT?

Topics: Customizing Orchard
Aug 1, 2011 at 10:14 PM


I'm trying to write a small site that requires lots of updates on the content so I figured it's best to build the page on the fly using XSLT.  Is it possible to incorporate that into Orchard? Can someone point me to the right place to look?  Thank you

Aug 2, 2011 at 12:04 AM

What does XSLT buy you that Razor templates don't? I mean, this is technically possible but I have a very hard time figuring out why you would do such a thing.

Aug 2, 2011 at 12:14 AM

Hi. Thank you for the reply. I'm new to ASP.NET and learning the MVC architecture. The guy who's working on the project, who I assist, has the content from marketing dept in an XML file and he formats it using XSLT to update the web content dynamically at run time, whenever marketing changes something.  He said it's quicker and easier without recoding things and we can just change out the XML file.  Is it better to use Razor templates?  If so, I would look into it.

So does that mean Orchard can change contents on the fly using Razor templates?  How do I go about looking into this in Orchard?  Thank you for the pointer.

Aug 2, 2011 at 12:19 AM

Razor templates are way easier to deal with than XSLT. Yes, you would be able to do the same stuff. This can give you a starting point:

Aug 2, 2011 at 12:22 AM

Man! I'm excited now!  I didn't know there's another way of doing it other than what was shown using XSLT.  Thanks a bunch!

Aug 2, 2011 at 12:52 AM


Actually, the reason why my project guy uses XSLT is because he calls a web service and it returns the XML content. From there, he formats it using XSLT and plops it on the aspx page where the container holds the content.  It might be a stupid question since I don't know Razor enough, but how can I transform the content from the web service with Razor?  Will the link you provided do the job?

Thank you

Aug 2, 2011 at 2:58 AM

Not exactly. If all you need is to format what a web service sends you, well you probably don't need Orchard for that. One would need to look at the details of what you are trying to do in order to determine the best course of action. In any case, taking XML and applying a XSLT is pretty much trivial in .NET, so it should be easy in Orchard as well.

Aug 3, 2011 at 5:15 PM

I know you're right about taking XML and applying XSLT is trivial.  I think I just don't know my way around Orchard yet, such as, which Razor form belongs to which page.  For example, I see http://localhost:30320/OrchardLocal/ but cannot locate the home page yet so I can see and play around with it.  However, my understanding is once I locate the page, I can go into the code page and edit as I normally would in any page, correct?  If that's so then I can customize the page by simply applying the XSLT, like you said.  Thank you so much Bertrandleroy!

Aug 3, 2011 at 8:12 PM

Ah well, in a CMS, the "pages" are stored in the database as a representation of their contents. When a request comes in, the CMS identifies what content is being requested and queries the database for it. It then dispatches the different parts of the content into specialized templates. So you will not find a specific file for the home page or any other page usually. What you will find is templates for smaller parts that then get assembled into a page.

The first thing to do would be perhaps to determine if you really need a CMS ;)

Aug 3, 2011 at 8:21 PM

:) Yes I do need the CMS because if anything, I like to have it for my personal use and from there, I'll get to learn from this awesome technique as well.  So how would I inject different contents inside a page besides doing it through the admin page?  Please excuse my lame questions.  I'm trying to get the Hello World up and running and see if I get a better feel of how this all works.  I'm trying to see if I can even tweak it so that I can insert XML content into your page, formatted by CSS.  You're saying with Razor, I won't need XSLT, so I will try that out. Thank you so much so far for being patient in answer my questions.

Aug 3, 2011 at 9:06 PM

Well, you can go different ways, with various complexity and flexibility:

- get data from web service in controller action, set the model to be that data, let the view transform that into HTML using Razor or, why not, XSLT. You are still firmly in MVC world but that would run fine in Orchard (although you don't get anything from that)

- get data from the web service in controller action, put shat into a shape result, let Orchard resolve templates that can take that shape and transform it into html. You are entering the Orchard realm: the page is already composed by Orchard, which opens the possibility of using the current theme and adding widgets around your content.

- get data from an Orchard part driver. Your content gets integrated into the Orchard content type system. You are now entirely using Orchard. You can make an aggregate content type that contains your web service data, plus comments from Orchard, ratings or who knows what.

Which approach you take depends on your specific requirements and what you're comfortable with.

Aug 3, 2011 at 9:20 PM

Definitely option 2 and 3 sounds good.  These two approaches are all in the documentation links right?  I just hope I understand how to do it.  I hope by going through all your tutorials and samples, I will be able to do the same for my project.

There are only a few pages that get changed dynamically by marketing people so hopefully I can handle this.  Orchard so far is an awesome project and this discussion board makes it that much better to have it as a choice.  Thank you!

Aug 3, 2011 at 9:33 PM

Cool, let us know how that goes.

Aug 8, 2011 at 11:56 PM

Update: So from the 3 options you gave me above, I tried the 1st method to learn first.  In the Controller Action, I made a class the does all the transforming and returned the string.  I passed that string into the ViewBag as follows:

public ActionResult Index()       
            ViewBag.RenderXslt = XsltTransformation.XsltTransform.TransformXml(XmlPath, XsltPath, null, null);
            return View("HelloWorld");

In the View, I simply did:


With this way of doing it, is it the right way to do it or is there a better way?

Next is to try the Shape Result that you suggested but I don't know how that works. Where can I read up on doing that?

Thank you 

Aug 9, 2011 at 12:00 AM

Well, it would be cleaner to handle that with a new type of action result, that would handle the transform. You would do something like return new XsltResult(XmlPath, XSltPath) and the Execute of the result type would do the transform. The way you are doing things, the controller is what is effectively rendering your view, which is clearly not ideal.

Aug 9, 2011 at 12:59 AM

Can you help me by being a bit more specific? What goes in the Controller and the View, so that I better understand what you mean bc I like what you're talking about.  Thank you

Aug 9, 2011 at 1:08 AM

You can start by reading this: The part about action results shows a number of classes that derive from ActionResult. Here is an example:, and another, and yet another, which is doing XML

Aug 9, 2011 at 1:24 AM

Thanks!  I'll get on it! :)