Copied to clipboard

Flag this post as spam?

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


  • Nicholas Westby 2005 posts 6843 karma points c-trib
    Jul 07, 2010 @ 00:08
    Nicholas Westby
    0

    Pass XSLT Macro Result To User Control

    Suppose I create an XSLT macro that gathers information about the current page and some of the child pages. Is there a way to pass the result of that XSLT macro to a .Net user control macro (i.e., rather than passing the result straight up to the rendered page)?

    What I would like to do is pass various bits of information to my .Net macro rather than just a single document property (and some of those bits of information might not be from the current document). I'm thinking passing the result of an XSLT macro to a .Net user control macro would be an ideal way of doing this, but I'm not sure if that is possible. Any ideas on how I might go about doing that?

    Oh, and I've read about calling.Net functions from XSLT and so on, but I'd really prefer knowing how to pass data from an XSLT macro to a .Net user control (not the other way around). Or maybe I can pass the current page ID to the .Net user control and interact with the API to run an XSLT macro against that page. That would be less than ideal, but if that's the only way then I would appreciate any information on that too.

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 07, 2010 @ 09:13
    Dirk De Grave
    0

    I don't understand why you'd pass xslt macro result to a .net control... why not write the complete logic into your .net user control? You can quite easily interact with the umbraco data using the nodeFactory class. Maybe I'm just missing your point here, so, would be nice if you could give us some more background info on what you're trying to do?

     

    Looking forward to your info.

     

    Cheers,

    /Dirk

     

  • Nicholas Westby 2005 posts 6843 karma points c-trib
    Jul 09, 2010 @ 23:34
    Nicholas Westby
    0

    Hi Dirk,

    Thanks for the reply. To answer your question, passing some XML to my user control seems like a perfectly reasonable way to transfer data to it. .Net has some convenient ways to deserialize XML into class instances. Assuming that is not possible, however, it sounds like this nodeFactory class is another way of doing it. For anybody who lands at this page after a search, see these pages for some discussions about nodeFactory:

    http://umbraco.org/documentation/books/api-cheatsheet/working-with-the-nodefactory

    http://forum.umbraco.org/yaf_postst4482_Basic-Question-Accessing-Umbraco-content-from-a-UserControl-using-the-API.aspx

    I haven't tried nodeFactory yet, but I'll make sure to keep a link to this post for when I do try it.

    To answer your other question, Dirk, I'm not really trying to do anything specific. I just want to know how to access Umbraco data for the current page and other pages from a .Net user control. Looks like nodeFactory may be what I'm looking for.

  • Nicholas Westby 2005 posts 6843 karma points c-trib
    Jul 10, 2010 @ 00:46
    Nicholas Westby
    0

    Oh, and another reason I wanted to pass the XML to a .Net user control was to visualize it (for debugging purposes and to learn the schema). But I'm thinking the preview feature in the XSLT designer is probably my best bet for that.

  • Sascha Wolter 615 posts 1101 karma points
    Jul 10, 2010 @ 17:43
    Sascha Wolter
    0

    Hi Nicholas,

    to lean the schema you can easily create a new XSLT script that just ouputs the content of the XML representation of a node in a template, i.e.

    <xsl:template match="/">
    <xsl:variable name="id" select="umbraco.library:RequestQueryString('id')" />
    <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>
    <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</xsl:text>
    <xsl:if test="$id &gt; 0">
    <xsl:choose>
       <xsl:when test="count(umbraco.library:GetXmlNodeById($id)/error) = 0">
           <xsl:copy-of select="umbraco.library:GetXmlNodeById($id)"/>
       </xsl:when>
       <xsl:when test="count(umbraco.library:GetMedia($id, 'false')/error) = 0">
           <xsl:copy-of select="umbraco.library:GetMedia($id, 'false')" />
       </xsl:when>
       <xsl:when test="count(umbraco.library:GetMember($id)/error) = 0">
           <xsl:copy-of select="umbraco.library:GetMember($id)" />
       </xsl:when>
    </xsl:choose>
    </xsl:if>
    </xsl:template>

    Then create a new document type with no further parameters and put the macro on the new template:

    <%@ Language="C#"  %>
    <umbraco:Macro Alias="GetXml" runat="server"></umbraco:Macro>

    After you have created a content node using the new document type you can browse to it and the XML structure will be presented to you, e.g.

    http://localhost/getXml.aspx?id=1064

     

    To make the XML/node data available in a .Net macro Umbraco provides more than enough ways to access it, like the nodeFactory Dirk has mentioned, or the Document, Media or Member objects. There is no need in this case to write your own code to generate an object representation of the XML/data as this is taken care of by the Umbraco dlls.

    Just hypothetically, if you desperately wanted to pass in some custom generated XML from your side that has been generated by an XSLT macro you could just take the same approach as with the getXml macro above, however you would then read the XML from your .Net macro, e.g.

    XmlDocument doc = new XmlDocument();

    doc.Load('http://localhost/getXml.aspx?id=1064');       //or was it doc.LoadXml?

    Given the nearly endless possibilities of Umbraco that seems like cumbersome.

    Sascha

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jul 10, 2010 @ 19:01
    Sebastiaan Janssen
    1

    Sascha I don't understand why you're going through all this trouble just to have a look at the schema, it's right there in the /data/umbraco.config file.. Sometimes to quickly debug the nodes that I'm working with at that moment I'll slap a textarea in it like so:

    <textarea>
      <xsl:copy-of select="$currentPage" />
    </textarea>
  • 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