First, there is no reason to reinvent the wheel, if you are alredy using an
xslt transform and it does everything you need it to do, leave it alone. On
your edit page you could use an xmldocument object to write/save the data in
the xml document. When the user displays the "View" page the xlst will
reload the xml file and display the edited/updated information. Make sure
the authentication method you have chosen has write access to the xml file,
I used "everyone - write".
Here is a working sample
There are six files in this example, two webforms (View.aspx, Edit.aspx),
two code behinds, an xml document and an xlst file. Set View.aspx as the
startup page.
Hope this helps.
'View.aspx
<HTML>
<HEAD>
<title>Defaul t</title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:button id="btnEdit" style="Z-INDEX: 101; LEFT: 12px; POSITION:
absolute; TOP: 13px" runat="server"
Text="Edit" Width="102px"></asp:button></form>
</body>
</HTML>
' End View.aspx
'View.aspx.vb
Public Class View
Inherits System.Web.UI.P age
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
Protected WithEvents btnEdit As System.Web.UI.W ebControls.Butt on
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
Dim doc As New System.Web.UI.W ebControls.Xml
Me.Controls.Add (doc)
doc.DocumentSou rce = "Books.xml"
doc.TransformSo urce = "Books.xslt "
End If
End Sub
Private Sub btnEdit_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnEdit.Click
Response.Redire ct("edit.aspx" )
End Sub
End Class
' End View.aspx.vb
'Edit.aspx
<HTML>
<HEAD>
<title>Edit</title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<div>
<asp:DropDownLi st id="lstBooks" runat="server" Width="189px"
AutoPostBack="T rue"></asp:DropDownLis t>
<asp:Button id="btnSave" runat="server" Width="131px"
Text="Save"></asp:Button>
<asp:Button id="btnDone" runat="server" Width="131px"
Text="Finished" ></asp:Button>
</div>
<div>
<table runat="server">
<tr width="100%">
<td width="30%">Aut hor</td>
<td runat="server">
<asp:TextBox id="txtAuthor" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Tit le</td>
<td>
<asp:TextBox id="txtTitle" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Gen re</td>
<td>
<asp:TextBox id="txtGenre" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Pri ce</td>
<td>
<asp:TextBox id="txtPrice" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Dat e Published</td>
<td>
<asp:TextBox id="txtPubDate " runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Des cription</td>
<td>
<asp:TextBox id="txtDescript ion" runat="server" Width="100%"
TextMode="Multi Line"></asp:TextBox></td>
</tr>
</table>
</div>
</form>
</body>
</HTML>
'End Edit.aspx
'Edit.aspx.vb
Public Class Edit
Inherits System.Web.UI.P age
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
Protected WithEvents btnSave As System.Web.UI.W ebControls.Butt on
Protected WithEvents lstBooks As System.Web.UI.W ebControls.Drop DownList
Protected WithEvents txtAuthor As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtTitle As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtGenre As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtPrice As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtPubDate As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtDescription As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnDone As System.Web.UI.W ebControls.Butt on
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Dim xDoc As System.Xml.XmlD ocument
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack _
AndAlso (Session.Item(" IsDirty") = True _
OrElse Session.Item("I sDirty") Is Nothing) Then
xDoc = New System.Xml.XmlD ocument
xDoc.Load(Serve r.MapPath("Book s.xml"))
Dim Nodes As System.xml.XmlN odeList = xDoc.SelectNode s("//book")
For Each Node As System.Xml.XmlN ode In Nodes
Me.lstBooks.Ite ms.Add(Node.Ite m("title").Inne rText)
Next
LoadData()
Session.Item("I sDirty") = False
End If
End Sub
Private Sub LoadData()
Me.txtAuthor.Te xt = GetElement("aut hor")
Me.txtDescripti on.Text = GetElement("des cription")
Me.txtGenre.Tex t = GetElement("gen re")
Me.txtPrice.Tex t = GetElement("pri ce")
Me.txtPubDate.T ext = GetElement("pub lish_date")
Me.txtTitle.Tex t = GetElement("tit le")
End Sub
Private Function GetElement(ByVa l TagName As String) As String
If xDoc Is Nothing Then
xDoc = New System.Xml.XmlD ocument
xDoc.Load(Serve r.MapPath("Book s.xml"))
End If
Dim Path As String = "//book[title=""" & Me.lstBooks.Sel ectedValue &
"""]"
Dim Node As System.Xml.XmlN ode = xDoc.SelectSing leNode(Path)
Return Node.Item(TagNa me).InnerText
End Function
Private Sub btnSave_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnSave.Click
If xDoc Is Nothing Then
xDoc = New System.Xml.XmlD ocument
xDoc.Load(Serve r.MapPath("Book s.xml"))
End If
Dim Path As String = "//book[title=""" & Me.lstBooks.Sel ectedValue &
"""]"
Dim node As System.Xml.XmlN ode = xDoc.SelectSing leNode(Path)
With node
.Item("title"). InnerText = Me.txtTitle.Tex t
.Item("author") .InnerText = Me.txtAuthor.Te xt
.Item("descript ion").InnerTex t = Me.txtDescripti on.Text
.Item("publish_ date").InnerTex t = Me.txtPubDate.T ext
.Item("price"). InnerText = Me.txtPrice.Tex t
.Item("genre"). InnerText = Me.txtGenre.Tex t
End With
xDoc.Save(Serve r.MapPath("book s.xml"))
Session.Item("I sDirty") = True
End Sub
Private Sub lstBooks_Select edIndexChanged( ByVal sender As Object, ByVal
e As System.EventArg s) Handles lstBooks.Select edIndexChanged
LoadData()
End Sub
Private Sub btnDone_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnDone.Click
Response.Redire ct("view.aspx" )
End Sub
End Class
'End Edit.aspx.vb
'Books.xslt
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="catalog" >
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD>Title</TD>
<TD>Author</TD>
<TD>Genre</TD>
<TD>Price</TD>
<TD>Date Published</TD>
<TD>Description </TD>
</TR>
<xsl:for-each select="book">
<TR>
<TD><xsl:valu e-of select="title"/></TD>
<TD><xsl:valu e-of select="author"/></TD>
<TD><xsl:valu e-of select="genre"/></TD>
<TD><xsl:valu e-of select="price" /></TD>
<TD><xsl:valu e-of select="publish _date" /></TD>
<TD><xsl:valu e-of select="descrip tion" /></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
'End Books.xslt
'Books.xml
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambard ella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer </genre>
<price>44.95</price>
<publish_date>2 000-10-01</publish_date>
<description> An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls , Kim</author>
<title>Midnig ht Rain</title>
<genre>Fantas y</genre>
<price>5.95</price>
<publish_date>2 000-12-16</publish_date>
<description> A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Coret s, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantas y</genre>
<price>5.95</price>
<publish_date>2 000-11-17</publish_date>
<description>Af ter the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
<book id="bk104">
<author>Coret s, Eva</author>
<title>Oberon 's Legacy</title>
<genre>Fantas y</genre>
<price>5.95</price>
<publish_date>2 001-03-10</publish_date>
<description> In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book id="bk105">
<author>Coret s, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantas y</genre>
<price>5.95</price>
<publish_date>2 001-09-10</publish_date>
<description>Th e two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.</description>
</book>
<book id="bk106">
<author>Randall , Cynthia</author>
<title>Lover Birds</title>
<genre>Romanc e</genre>
<price>4.95</price>
<publish_date>2 000-09-02</publish_date>
<description>Wh en Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.</description>
</book>
<book id="bk107">
<author>Thurman , Paula</author>
<title>Splish Splash</title>
<genre>Romanc e</genre>
<price>4.95</price>
<publish_date>2 000-11-02</publish_date>
<description> A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book id="bk108">
<author>Knorr , Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror </genre>
<price>4.95</price>
<publish_date>2 000-12-06</publish_date>
<description> An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
<book id="bk109">
<author>Kress , Peter</author>
<title>Parado x Lost</title>
<genre>Scienc e Fiction</genre>
<price>6.95</price>
<publish_date>2 000-11-02</publish_date>
<description>Af ter an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.</description>
</book>
<book id="bk110">
<author>O'Brien , Tim</author>
<title>Microsof t .NET: The Programming Bible</title>
<genre>Computer </genre>
<price>36.95</price>
<publish_date>2 000-12-09</publish_date>
<description>Mi crosoft's .NET initiative is explored in
detail in this deep programmer's reference.</description>
</book>
<book id="bk111">
<author>O'Brien , Tim</author>
<title>MSXML3 : A Comprehensive Guide</title>
<genre>Computer </genre>
<price>36.95</price>
<publish_date>2 000-12-01</publish_date>
<description>Th e Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.</description>
</book>
<book id="bk112">
<author>Galos , Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer </genre>
<price>49.95</price>
<publish_date>2 001-04-16</publish_date>
<description>Mi crosoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.</description>
</book>
</catalog>
'End Books.xml
"Glenn M" <gl**********@b t.com> wrote in message
news:32******** *************** ***@posting.goo gle.com...
I have a shared XML file on a server .
i also have one xslt file that performs a simple transform on in to
view the data.
now i want to have another page that lets users modify the shared xml
file via some editable controls such as text boxes , option boxes etc.
how can i implment this , should i use another xslt file with <INPUT>
controls . if so how can i save the result back using the asp.net
page.
or should i use asp.net to drive the whole page and not use an xslt
file . again , any pointers on how to do this would be useful.
thanks
glenn