Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jesper Hauge 298 posts 486 karma points c-trib
    Jan 19, 2010 @ 11:47
    Jesper Hauge
    0

    Easiest way to render xslt file from code

    While I'm studying the linq-to-umbraco features I still have to deliver on a project so:

    Basically I'd like to render different umbraco xslt files, based on decisions made in a masterpage codebehind. The xslt transformation has to take place like when the transformation is done by an umbraco:Macro, but I'd like to dynamically select which xslt file is used, or alternatively which alias is used for the macro, so I can have multiple macros each calling different xslt-files.

    I've tried setting the macro alias in code like this: 

    MacroId.Alias = "MyMacroAlias";

    Both i Page_Load and Page_Prerender, but this results in the macro not running, it just outputs "<Macro:  (,)>" into the page output.

    What I'd really like to do was use the Api to run the xslt transformation, so that I didn't need the macro at all, but I haven't been able to turn up any pages explaining how that can be done. 

    Any ideas?

    Regards
    Jesper Hauge

  • René Pjengaard 114 posts 675 karma points c-trib
    Jan 22, 2010 @ 13:31
    René Pjengaard
    0

    Hi Jesper,

    i have the exact same problem. I wan´t to render a document with a xslt file direct from my code-behind-file. I know i can use xslttransform in .NET, but is there a "right" way to do it in Umbraco. Have you found any solution yet?

     

    Regards
    René Pjengaard

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 22, 2010 @ 13:42
    Tim Geyssens
    0

    Hi René,

    Check out the locator sourecode, I do some xslt transformations from a usercontrol in there.

    http://locator4umbraco.codeplex.com/

     

     

  • Petr Snobelt 923 posts 1534 karma points
    Jan 22, 2010 @ 13:49
    Petr Snobelt
    0

    Take a look at xsltResult project, it allow you to specify xslt style as parameter, maybe it can be changed at runtime. But it use caching by default, so don't remember to disable it.

    Petr

  • Jesper Hauge 298 posts 486 karma points c-trib
    Jan 22, 2010 @ 23:20
    Jesper Hauge
    0

    Thanks Tim

    Checked out the locator sourcecode (or actually I chose the lazy way, downloaded the package, and popped the Nibble.Umb.Locator.dll open in reflector). I presume the code you're talking about is 

    this.litResults.Text = macro.GetXsltTransformResult(content.Instance.XmlContent, macro.getXslt(this.ResultsXslt));

    in the Locator usercontrol Page_load. Looks like it is exactly what I was asking for.

    However this still requires the creation of a macro, and it got me thinking how much nicer it would be to be able to do this with an umbraco tag like, 

    <umbraco:XsltTransform XsltFile="MyFile.xslt" runat="server" />

    So went to check if there was any issues around this i codeplex. Turns out there was one, which I would recommend you voted up, the issue can be found here. This search also turned up a page written by Kasper B outlining a method to achieve something like the above umbraco-tag.

    Regards
    Jesper Hauge

  • Jesper Hauge 298 posts 486 karma points c-trib
    Jan 22, 2010 @ 23:27
    Jesper Hauge
    0

    And thanks petr - checking out the XsltResult project right now!

    As far as I can see it does exactly what I didn't know I wanted until now.

    Regards
    Jesper

    P.S. Giving the answer to Petr (partly because I'm a big fan of Mr.Incredible)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies