亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄 搜尋
XSLT 基礎(chǔ)教程 XSL 語言 XSLT 簡介 XSLT 瀏覽器 XSLT - 轉(zhuǎn)換 XSLT <xsl:template> 元素 XSLT <xsl:value-of> 元素 XSLT <xsl:for-each> 元素 XSLT <xsl:sort> 元素 XSLT <xsl:if> 元素 XSLT <xsl:choose> 元素 XSLT <xsl:apply-templates> 元素 XSLT - 在客戶端 XSLT - 在服務(wù)器端 XSLT - 編輯 XML XML 編輯器 XSLT 元素參考手冊(cè) XSLT <xsl:apply-imports> 元素 XSLT <xsl:apply-templates> 元素 XSLT <xsl:attribute> 元素 XSLT <xsl:attribute-set> 元素 XSLT <xsl:call-template> 元素 XSLT <xsl:choose> 元素 XSLT <xsl:comment> 元素 XSLT <xsl:copy> 元素 XSLT <xsl:copy-of> 元素 XSLT <xsl:decimal-format> 元素 XSLT <xsl:element> 元素 XSLT <xsl:fallback> 元素 XSLT <xsl:for-each> 元素 XSLT <xsl:if> 元素 XSLT <xsl:import> 元素 XSLT <xsl:include> 元素 XSLT <xsl:key> 元素 XSLT <xsl:message> 元素 XSLT <xsl:namespace-alias> 元素 XSLT <xsl:number> 元素 XSLT <xsl:otherwise> 元素 XSLT <xsl:output> 元素 XSLT <xsl:param> 元素 XSLT <xsl:preserve-space> 和 <xsl:strip-space> 元素 XSLT <xsl:processing-instruction> 元素 XSLT <xsl:sort> 元素 XSLT <xsl:stylesheet> 和 <xsl:transform> 元素 XSLT <xsl:template> 元素 XSLT <xsl:text> 元素 XSLT <xsl:value-of> 元素 XSLT <xsl:value-of> 元素 XSLT <xsl:variable> 元素 XSLT <xsl:when> 元素 XSLT <xsl:with-param> 元素 XSLT 函數(shù) XSLT current() 函數(shù) XSLT document() 函數(shù) XSLT element-available() 函數(shù) XSLT format-number() 函數(shù) XSLT function-available() 函數(shù) XSLT generate-id() 函數(shù) XSLT key() 函數(shù) XSLT system-property() 函數(shù) XSLT unparsed-entity-uri() 函數(shù)
文字

XSLT - 編輯 XML



存儲(chǔ)在 XML 文件中的數(shù)據(jù)可通過因特網(wǎng)瀏覽器進(jìn)行編輯。


打開、編輯并保存 XML

現(xiàn)在,我們會(huì)為您展示如何打開、編輯及保存存儲(chǔ)于服務(wù)器上的 XML 文件。

我們將使用 XSL 把 XML 文檔轉(zhuǎn)換到一個(gè) HTML 表單中。XML 元素的值會(huì)被寫到 HTML 表單中的 HTML 輸入域。這個(gè) HTML 表單是可編輯的。在被編輯完成后,數(shù)據(jù)會(huì)被提交回服務(wù)器,XML 文件會(huì)得到更新(這部分由 ASP 完成)。


XML 文件和 XSL 文件

首先,請(qǐng)看將被使用的 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>

接著,請(qǐng)看下面的樣式表("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.html">
<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>

上面這個(gè) XSL 文件會(huì)循環(huán)遍歷 XML 文件中的元素,并為每個(gè) XML "field" 元素創(chuàng)建一個(gè)輸入域。XML "field" 元素的 "id" 屬性的值被添加到每個(gè) HTML 輸入域的 "id" 和 "name" 屬性。每個(gè) XML "value" 元素的值被添加到每個(gè) HTML 輸入域的 "value" 屬性。結(jié)果是,可以得到一個(gè)包含 XML 文件中值的可編輯的 HTML 表單。

然后,我們還有第二個(gè)樣式表:"tool_updated.xsl"。這個(gè) XSL 文件會(huì)被用來顯示已更新的 XML 數(shù)據(jù)。這個(gè)樣式表不會(huì)輸出可編輯 HTML 表單,而是一個(gè)靜態(tài)的 HTML 表格:

<?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 文件

在上面 "tool.xsl" 文件中,HTML 表單的 action 屬性的值是 "edittool.asp" 。

"edittool.asp" 頁面包含兩個(gè)函數(shù):loadFile() 函數(shù)載入并轉(zhuǎn)換 XML 文件,updateFile() 函數(shù)更新 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
%>

提示:假如您不了解如何編寫 ASP,請(qǐng)學(xué)習(xí)我們的 ASP 教程。

注意:我們正在轉(zhuǎn)換并更新位于服務(wù)器上的 XML 文件。這是一個(gè)跨平臺(tái)的解決方案。客戶端僅能獲得從服務(wù)器返回的 HTML - 而 HTML 可運(yùn)行于任何瀏覽器。


上一篇: 下一篇: