داده های ذخیره شده در یک سند xml توسط مرورگر می توانند ویرایش شوند
open , edit , save یک سند xml هم اکنون به شما اموزش داده می شود که چطور می توان داده های یک سند xml که در سرور ذخیره شده باز کرد ویرایش کرد و ذخیره  کردما خواهیم آموخت چطور می توان داده های یک سند xml را از طریق xslt به صورت html انتقال دهیم مقادیر دورن تگ های سند xml را می توان در فیلدهای ورودی فرم هایی که توسط دستورات html ایجاد می شوند قرار داد شما می دانید که می توان محتوای دورن خانه های دریافت داده فرم های html را ویرایش کرد بعد از ویرایش این داده ها ، محتوای فرم html دوباره به سرور بر خواهند گشت و سند xml با محتوای جدید به روز خواهد شد که این قسمت اخری توسط دستورات زبان asp انجام می شود

 فایل xml و فایل xslt

ابتدا به محتوای سند xml که نام ان tool.xml است توجه کنید :

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<tool>
<field id=”prodName”>
<value>HAMMER HG2606</value>
</field>
<field id=”prodNo”>
<value>32456240</value>
</field>
<field id=”price”>
<value>$30.00</value>
</field>
</tool>

حالا به برنامه tool.xsl توجه نمائید :

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<xsl:stylesheet version=”1.0″
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>

<xsl:template match=”/”>
<html>
<body>
<form method=”post” action=”edittool.asp”>
<h2>Tool Information (edit):</h2>
<table border=”0″>
<xsl:for-each select=”tool/field”>
<tr>
<td><xsl:value-of select=”@id”/></td>
<td>
<input type=”text”>

<xsl:attribute name=”id”>
<xsl:value-of select=”@id” />
</xsl:attribute>

<xsl:attribute name=”name”>
<xsl:value-of select=”@id” />
</xsl:attribute>

<xsl:attribute name=”value”>
<xsl:value-of select=”value” />
</xsl:attribute>

</input>
</td>
</tr>
</xsl:for-each>
</table>
<br />
<input type=”submit” id=”btn_sub” name=”btn_sub” value=”Submit” />
<input type=”reset” id=”btn_res” name=”btn_res” value=”Reset” />
</form>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

دستورات xslt بالا روی تگ های سند xml حلقه ای ایجاد می کند

و برای هر تگ سند xml  که نام ان filed است یک فیلد وروردی یا همان input ایجاد می نماید مقدار id تگ های با نام field سند xml ما به مقدار صفت های id , name تمام تگ های input فرم افزوده می شود مقدار هر تگ value اضافه می شود به صفت value هر فیلد ورودی html نتیجه فرم قابل ویرایشی است که مقدار هر فیلد ان محتوای تگ های xml است
حالا ما برنامه دیگری به نام tool_updated.xsl را داریم از این برنامه xsl برای نمایش مقادیر بروز شده xml بکار می رود این برنامه از یک جدول بدون تغییر استفاده می کند نه از یک فرم که بشود مقادیر دورن فیلدهای ان را تغییر داد

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<xsl:stylesheet version=”1.0″
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>

<xsl:template match=”/”>
<html>
<body>
<h2>Updated Tool Information:</h2>
<table border=”1″>
<xsl:for-each select=”tool/field”>
<tr>
<td><xsl:value-of select=”@id” /></td>
<td><xsl:value-of select=”value” /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

برنامه به زبان ASP مقدار صفت action  فرمی که در برنامه tool.xsl بالا داشتیم ، برابر edittool.asp بود
فایل edittool.asp شامل دو تابع است :

الف :

تابع loadFile که سند xml را بار گذاری می کند و انتقال می دهد برای نمایش داده شدن

ب:

فایل updateFile که تغییرات در محتوا را در سند xml اعمال می کند

<%
function loadFile(xmlfile,xslfile)
Dim xmlDoc,xslDoc
‘Load XML file
set xmlDoc = Server.CreateObject(“Microsoft.XMLDOM”)
xmlDoc.async = false
xmlDoc.load(xmlfile)
‘Load XSL file
set xslDoc = Server.CreateObject(“Microsoft.XMLDOM”)
xslDoc.async = false
xslDoc.load(xslfile)
‘Transform file
Response.Write(xmlDoc.transformNode(xslDoc))
end function

function updateFile(xmlfile)
Dim xmlDoc,rootEl,f
Dim i
‘Load XML file
set xmlDoc = Server.CreateObject(“Microsoft.XMLDOM”)
xmlDoc.async = false
xmlDoc.load(xmlfile)

‘Set the rootEl variable equal to the root element
Set rootEl = xmlDoc.documentElement

‘Loop through the form collection
for i = 1 To Request.Form.Count
‘Eliminate button elements in the form
if instr(1,Request.Form.Key(i),”btn_”)=0 then
‘The selectSingleNode method queries the XML file for a single node
‘that matches a query. This query requests the value element that is
‘the child of a field element that has an id attribute which matches
‘the current key value in the Form Collection. When there is a match –
‘set the text property equal to the value of the current field in the
‘Form Collection.
set f = rootEl.selectSingleNode(“field[@id='” & _
Request.Form.Key(i) & “‘]/value”)
f.Text = Request.Form(i)
end if
next

‘Save the modified XML file
xmlDoc.save xmlfile

‘Release all object references
set xmlDoc=nothing
set rootEl=nothing
set f=nothing

‘Load the modified XML file with a style sheet that
‘allows the client to see the edited information
loadFile xmlfile,server.MapPath(“tool_updated.xsl”)
end function

‘If the form has been submitted update the
‘XML file and display result – if not,
‘transform the XML file for editing
if Request.Form(“btn_sub”)=”” then
loadFile server.MapPath(“tool.xml”),server.MapPath(“tool.xsl”)
else
updateFile server.MapPath(“tool.xml”)
end if
%>

ما ارسال و اعمال تغییرات در سند xml را در سرور انجام دادیم

کلاینت ها یا همان کامپیوترهای کاربر فقط فایل html را از سرور بعنوان نتیجه کار دریافت خواهد کرد که فایلهای html بدون هیچ مشکلی در رایانه کاربران اجرا می شوند