I have a number of Umbraco 4.0.3 sites and I would like to be able to pull the contents of a list from one of them into the other using XSLT if possible. The list is actually going to be a list of URL's to the other sites in the group but what I want to know is am I going to be able to do this using XSLT? Would I need to output the list as XML then using XSLT to bring it into the other sites? I actually want the list to randomly pull in three items but I think I should be ok working out how to do that (I have done random lists before) as long as I can work out how I pull in the data in the first place. Any suggestions?
If the sites are not in the same umbraco installation, sharing the same content tree, then you'll need to treat this more or less as you would an RSS feed.
On the 'sharing' site, create a template with a macro that outputs your list in an xml format (see the rss feed macro template for ideas). Just like with an RSS feed you will show the output using an alternate template (the ?altTemplate syntax). That's all that is needed on the 'sharing' site.
On the 'consuming' site, create a macro that uses the umbraco.library:GetXmlDocumentByUrl(). The url will be to the 'sharing' site. Probably something like: http://www.example.com/default.aspx?altTemplate=mySharingTemplateAlias. Just substitute the real domain and the real template alias for the 'sharing' site.
At this point your macro will fetch the xml output of the list of urls from the 'sharing' site and you'll have that xml in a variable, which you can then loop through to display the links the way you want.
Hi Doug, I got a bit confused with the RSS feed and couldn't get it to work so I have created my own XSLT as follows but what else do I need to make it output as an XML file?
I now have this working correctly using the following code, it now randomly pulls in 3 website links but the last thing I need to do is make it so that it doesn't pull in a link to the current page if this is possible. Therefore if I am currently on http://www.mytestsite.com/default.aspx then I do not want it to list a link to http://www.mytestsite.com. Anyone know if this is possible and how I would go about doing this? I'm assuming I would need some sort of IF statement that checks the current URL and compares it to the ones in the list?
<msxsl:script language="c#" implements-prefix="randomTools"> <msxsl:assembly href="../bin/umbraco.dll"/> <![CDATA[ /// <summary> /// Gets a random integer that falls between the specified limits /// </summary> /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param> /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param> /// <returns>A random integer within the specified range</returns> public static int GetRandom(int lowerLimit,int upperLimit) { Random r = umbraco.library.GetRandom(); int returnedNumber = 0; lock (r) { returnedNumber = r.Next(lowerLimit, upperLimit); } return returnedNumber; } ]]> </msxsl:script> </xsl:stylesheet>
<msxsl:script language="c#" implements-prefix="randomTools"> <msxsl:assembly href="../bin/umbraco.dll"/> <![CDATA[ /// <summary> /// Gets a random integer that falls between the specified limits /// </summary> /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param> /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param> /// <returns>A random integer within the specified range</returns> public static int GetRandom(int lowerLimit,int upperLimit) { Random r = umbraco.library.GetRandom(); int returnedNumber = 0; lock (r) { returnedNumber = r.Next(lowerLimit, upperLimit); } return returnedNumber; } ]]> </msxsl:script>
Pull in list from other Umbraco sites using XSLT
Hi,
I have a number of Umbraco 4.0.3 sites and I would like to be able to pull the contents of a list from one of them into the other using XSLT if possible. The list is actually going to be a list of URL's to the other sites in the group but what I want to know is am I going to be able to do this using XSLT? Would I need to output the list as XML then using XSLT to bring it into the other sites? I actually want the list to randomly pull in three items but I think I should be ok working out how to do that (I have done random lists before) as long as I can work out how I pull in the data in the first place. Any suggestions?
If the sites are not in the same umbraco installation, sharing the same content tree, then you'll need to treat this more or less as you would an RSS feed.
On the 'sharing' site, create a template with a macro that outputs your list in an xml format (see the rss feed macro template for ideas). Just like with an RSS feed you will show the output using an alternate template (the ?altTemplate syntax). That's all that is needed on the 'sharing' site.
On the 'consuming' site, create a macro that uses the umbraco.library:GetXmlDocumentByUrl(). The url will be to the 'sharing' site. Probably something like: http://www.example.com/default.aspx?altTemplate=mySharingTemplateAlias. Just substitute the real domain and the real template alias for the 'sharing' site.
At this point your macro will fetch the xml output of the list of urls from the 'sharing' site and you'll have that xml in a variable, which you can then loop through to display the links the way you want.
Make sense?
cheers,
doug.
Hi Doug, I got a bit confused with the RSS feed and couldn't get it to work so I have created my own XSLT as follows but what else do I need to make it output as an XML file?
Please ignore this, I remembered I have already asked this before.
I now have this working correctly using the following code, it now randomly pulls in 3 website links but the last thing I need to do is make it so that it doesn't pull in a link to the current page if this is possible. Therefore if I am currently on http://www.mytestsite.com/default.aspx then I do not want it to list a link to http://www.mytestsite.com. Anyone know if this is possible and how I would go about doing this? I'm assuming I would need some sort of IF statement that checks the current URL and compares it to the ones in the list?
Once again, I have managed to resolve it using the following code, thanks Doug, I shall mark your answer as the solution:
is working on a reply...