Tuesday, July 11, 2006

ASP.NET Web.Config from IIS

No comments:
Just a little tip for those that dont like hacking the XML in web.config on ASP.NET 2.0 projects manually theres a handy little tool built into IIS:
If you right click on the website in IIS then click properties then go to the ASP.NET tab theres a button at the bottom called Edit Configuration, if you go in there theres a nice little interface for the web.config file which saves you hacking the XML directly!
Read More

Tuesday, July 04, 2006

RSS XML Stylesheet Example

No comments:

Some time ago I was working for a client who required their CMS system to output particular items as RSS feeds. The CMS output XML and used XSLT to tranform to HTML. This provided a very handy mechanism indeed for conversion to RSS.

 

My final solution used a stylesheet to simply take the XML from the CMS and convert it to an RSS 2.0 format feed rather than HTML! Below I have rewritten the stylesheet (adding a few flourishes) which should be easily adaptable and fairly generic for this type of conversion as long as the XML provides the following attributes in a fairly sensible format!

 

XML Needs to contain the following items for the feed:

    TITLE OF FEED

    LINK TO FEED HOMEPAGE

    DESCRIPTION OF FEED

    COPYRIGHT NOTICE

 

XML Needs to contain the following items for EACH ARTICLE:

    TITLE OF ARTICLE

    LINK TO ARTICLE

    DESCRIPTION OF ARTICLE

    CREATOR OF ARTICLE

    DATE OF ARTICLE

 

An eaxmple of how the XML might look is (it might not look at all like this in which case I might advise a pre-RSS xml conversion with XSL to bring it into line with the below and separate the XML conversion code form the XML-RSS code):

 

<data>

  <feed title="" link="description="" copyright="">

    <item>

     <title></title>

     <link></link>

     <description></description>

     <creator></creator>

     <date></date>

    </item>

    <item>

     <title></title>

     <link></link>

     <description></description>

     <creator></creator>

     <date></date>

    </item>

    <item>

     <title></title>

     <link></link>

     <description></description>

     <creator></creator>

     <date></date>

    </item>

  </feed>

</data>

 

And finally the actual stylesheet - obviously this could easily be extended to manage multiple feed xml but if I did it all here it'd take the fun out of it!

 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="no" encoding="unicode" omit-xml-declaration="yes" media-type="text/xml"/>

 

<xsl:template match="data">

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">

<channel>

  <title>TITLE OF FEED</title>

  <link>LINK TO FEED HOMEPAGE</link>

  <description>DESCRIPTION OF FEED</description>

  <language>en-gb</language>

  <dc:rights>COPYRIGHT NOTICE</dc:rights>

  <xsl:for-each select="ITEMNODESET">

  <item>

      <title>TITLE OF ARTICLE</title>

      <link>LINK TO ARTICLE</link>

      <description>DESCRIPTION OF ARTICLE</description>

      <dc:creator>CREATOR OF ARTICLE</dc:creator>

      <dc:date>DATE OF ARTICLE</dc:date>   

  </item>

  </xsl:for-each>

</channel>

</rss>           

</xsl:template>

</xsl:stylesheet>

 

 

Read More

XSLT Replace Template

No comments:
I was working on a site today that required me to split a string in the form of a=1;b=2;c=3 in xsl. Now xsl does provide a translate() function but it doesn't traverse the whole string doing a normal replacement as you might expect. Instead a trawled the internet and found the following little template which nicely recurses through and does the replacement. I thought I'd post it here so I can find it again - and share it with the world of course!
 

  <xsl:template name="replace">

    <xsl:param name="string" select="." />

    <xsl:choose>

      <xsl:when test="not($string)" />

      <xsl:when test="contains($string, ';')">

        <xsl:value-of select="substring-before($string, ';')" />

        <br />

        <xsl:call-template name="replace">

          <xsl:with-param name="string" select="substring-after($string, ';')" />

        </xsl:call-template>

      </xsl:when>

      <xsl:otherwise>

        <xsl:value-of select="$string" />

        <br />

      </xsl:otherwise>

    </xsl:choose>

  </xsl:template>

 

All you need do is call the template and pass your input into with $string param, in my case this was the ";". Then replace the <br/> tags with whatever you need to replace your input string with - easy!

Read More

Monday, July 03, 2006

Email Blog Entry

1 comment:
Again Im new to all this blogging lark and now Ive had it for a while I thought I'd checkout some of the extended capabilities - like emailing in this entry! See you all again soon!
Oh I've also allowed comments from everyone (not just registered users) so lets see if we can get some kinda flame ware on the go eh? ;oP

Read More

Enmus, Enum Sets, parsing n' stuff

No comments:
Recently I have started keeping track of some industry leading developers and what they're up to via their weblogs. One very active blogger is Rick Strahl who really knows his stuff - anyway todya I noticed he'd posted a very good guide to using Enum's - far far superior to my one liner about recursing through them so I thought Id post a link here and share!

http://west-wind.com/weblog/posts/6222.aspx
Read More