Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Asp.net, xml and xsl newbie

Status
Not open for further replies.

jordan11

Technical User
May 24, 2003
150
0
0
GB
Hi,

I trying to write an application that will allow a user to go in and see a list of articles, once they selects an article they should have the options to delete,edit or add new article.

I am doing this using asp.net (vb), xml and xsl.


At the moment I am able to display a page using using the above methods but I am not sure how to edit delete or add new. Also on save the data is saved to 2 xml documents.





This is the xml I am using

site_map.xml


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="site_map.xsl"?>
<levels>
<level1 id="1" title="article1" teaser="all about article3" show=""/>
<level1 id="2" title="article2" teaser="all about article3"show="" />
<level1 id="3" title="article3" teaser="all about article3" show="" />
</levels>

each Id has its own content
so this is an e.g of the content for id="1" so on save if I am adding a new article the title will be saved in site_map.xml with a new id and and create a new content using the new id in paggecontet.xml as the name of the xml so at the moment I have content saved as

1.xml
2.xml
3.xml

which are all link to the site_map.xml
<?xml version="1.0"?>

<page>

<pagecontentblocks>
<pagecontent><![CDATA[<strong>article 1</strong> test data 1]]></pagecontent>
</pagecontentblocks>
</page>


This xsl displays all the information in site_map xml and gives the user the option to add, delete, edit and save

edit.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="html" />

<xsl:param name="pgid" select="1"/>

<xsl:template match="/">

<xsl:call-template name="content"/>

</xsl:template>
<xsl:template name="content">
<tr><td id="{@id}"><a title="Follow link to add new article"
href="cms_edit.aspx?" ><b>Add a new article</b></a></td></tr>
<xsl:for-each select="levels/level1">
<tr>
<td>
<span><xsl:value-of select="@title" /></span></td>
<td id="{@id}"><a title="Follow link for {@title}"
href="cms_edit.aspx?pageID={@id}&amp;title={@title}" > Edit</a>
</td>
<td><a
title="link for {@name}"
href="delete.aspx?pageID={@id}&amp;title={@title}" >Delete</a>
</td>
</tr>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
 
This isn't the way you'd want to do things with ASP.NET.

ASP.NET provides a rich set of "Server Controls" which are usually placeholders for content. Server Controls have a very rich programming model behind them and basically turn static html into Windows-style controls that make it easy to manipulate formatting, bind data, and handle client-side events on the server side (through a little bit of PostBack Voo Doo).

In other words, instead of using an XSL template which repeats a section of static HTML for every "article", you'd use a DataList, setup element templates and binding, then set its DataSource property to your data and call DataBind().

It's a lot easier to work with than XSL and has a lot more power behind it. For example, any formatting or layout changes with your template would require manual tweaks to the HTML in the template, whereas you can use the Visual Studio designer with the DataList. Also, as you're experiencing, it's inobvious how to add "Edit", "Add" and "Delete" buttons and hook them into the ASP.NET Framework. With a DataList, you just drag a LinkButton or Button into the ItemTemplate of the DataList.

You also have control over things like alternating background colors for each item and X-number of columns and Y-number of rows should you want to change the layout.

Anyway, the point is that you may want to rethink the approach.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top