Download Advertiser - 44.3 KB
Introduction
lately I've been playing with xml/xslt transformation and just noticed how easy I can produce whatever contents from plain xml files, overriding my traditional time-consuming technique of parsing xml, I decided to play a lettle pit with my Advertiser module, which can be of use on websites when you want to host people's advertises. this module should do it without database at all.
Using the code
First here's the structure of the sample website:
Advertiser(root)
|
|--->Admin [Amin area]
| |
| |--->Advertiser
| |
| |--->Add.aspx [add files to locations]
| |
| |--->Default.aspx [display/edit/delete files]
| |
| |--->Edit.aspx [edit files]
|
|
|---->App_Code
| |
| |--->Advertiser
| |
| |--->AddevrtiserManager.cs
|
|
|----->SiteScripts
| |
| |--->flashfix.js [used to render flash]
|
|---->uc
| |
| |--->Advertiser.ascx [user control displays the transformed file]
|
|
|---->UploadedData [+r/+w permission required]
| |
| |---->Advertiser
| |
| |--->config [Configuraion files]
| | |
| | |--->Advertiser.xml
| | |--->Advertiser.xslt
| |
| |----> [Ad. files]
|
|---->Default.aspx [Test page]
The Xml file looks like this :
="1.0" ="utf-8"
<Advertiser>
<addvert type="Front_Content_Bottom">
<item id="4cf7f1f6-614a-4810-88f6-c73d681e9e61">
<type>FlashMovie</type>
<path>/UploadedData/Advertiser/4cf7f1f6-614a-4810-88f6-c73d681e9e61.swf</path>
<width>500</width>
<height>100</height>
</item>
</addvert>...
<xsl:param name="ExternalParameter"></xsl:param>
<xsl:param name="AdvType">AnimatedGif</xsl:param>
<xsl:template match="/">
<xsl:apply-templates select="Advertiser/addvert"/>
</xsl:template>
<xsl:template match="addvert">
<xsl:choose>
<xsl:when test="@type=$ExternalParameter">
<table cellpadding="0" cellspacing="0" border="0" id="tbl">
<xsl:for-each select="item">
<tr>
<xsl:choose>
<xsl:when test="contains(type, $AdvType)">
<td>
<a target="_blank">
<xsl:if test="string-length(normalize-space(url)) > 0">
<xsl:attribute name="href">
<xsl:value-of select="url" />
</xsl:attribute>
</xsl:if>
<img border="0">
<xsl:attribute name="src">
<xsl:value-of select="path" />
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="width" />
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="height" />
</xsl:attribute>
</img>
</a>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<script type="text/javascript">
RenderFlash('<xsl:value-of select="path" />', <xsl:value-of select="width" />, <xsl:value-of select="height" />);
</script>
</td>
</xsl:otherwise>
</xsl:choose>
...............
The display page is based on a user control "Advertiser.ascx" with a property "Location" which tells the control to fetch the advertises in that belongs to this specefic location.
private Advertiser.Location _Location;
While in the Admin area I decided to play dirty parsing the xml manually, to show the difference beteen the xslt style and the hard code one, although during the developement I was confronted by this annoying delima, how can I use xslt to fetch specefic location's ads and displaying them separetly in a datagrid along with eidt and delete controls.
In the user control there was no problem retrieving the ads of a location and render them directely on the control area, but I didn't manage to go arround that to feed them to a datagrid at the moment.
Points of Interest
It is quite interesting in fact how xslt simplifies the work with xml data, that is the core of this project
History
Keep a running update of any changes or improvements you've made here.