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.
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?
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:
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.
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.
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 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:
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.
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
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.
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.
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: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>
Then create a new document type with no further parameters and put the macro on the new template:
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
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:
is working on a reply...
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.