{"id":248395,"date":"2022-08-03T08:28:53","date_gmt":"2022-08-03T00:28:53","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=248395"},"modified":"2022-07-22T11:29:19","modified_gmt":"2022-07-22T03:29:19","slug":"editing-xml-overview","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/editing-xml-overview.html","title":{"rendered":"XSLT – \u7f16\u8f91 XML\u6982\u8ff0"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5b58\u50a8\u5728 XML \u6587\u4ef6\u4e2d\u7684\u6570\u636e\u53ef\u901a\u8fc7\u56e0\u7279\u7f51\u6d4f\u89c8\u5668\u8fdb\u884c\u7f16\u8f91\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u6253\u5f00\u3001\u7f16\u8f91\u5e76\u4fdd\u5b58 XML<\/strong><\/div>\n

\u73b0\u5728\uff0c\u6211\u4eec\u4f1a\u4e3a\u60a8\u5c55\u793a\u5982\u4f55\u6253\u5f00\u3001\u7f16\u8f91\u53ca\u4fdd\u5b58\u5b58\u50a8\u4e8e\u670d\u52a1\u5668\u4e0a\u7684 XML \u6587\u4ef6\u3002<\/p>\n

\u6211\u4eec\u5c06\u4f7f\u7528 XSL \u628a XML \u6587\u6863\u8f6c\u6362\u5230\u4e00\u4e2a HTML \u8868\u5355\u4e2d\u3002XML \u5143\u7d20\u7684\u503c\u4f1a\u88ab\u5199\u5230 HTML \u8868\u5355\u4e2d\u7684 HTML \u8f93\u5165\u57df\u3002\u8fd9\u4e2a HTML \u8868\u5355\u662f\u53ef\u7f16\u8f91\u7684\u3002\u5728\u88ab\u7f16\u8f91\u5b8c\u6210\u540e\uff0c\u6570\u636e\u4f1a\u88ab\u63d0\u4ea4\u56de\u670d\u52a1\u5668\uff0cXML \u6587\u4ef6\u4f1a\u5f97\u5230\u66f4\u65b0\uff08\u8fd9\u90e8\u5206\u7531 ASP \u5b8c\u6210\uff09\u3002<\/p>\n

XML \u6587\u4ef6\u548c XSL \u6587\u4ef6<\/strong><\/div>\n

\u9996\u5148\uff0c\u8bf7\u770b\u5c06\u88ab\u4f7f\u7528\u7684 XML \u6587\u6863\uff08\"tool.xml\"\uff09\uff1a<\/p>\n

\r\n<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<tool>\r\n<field id=\"prodName\">     \r\n<value>HAMMER HG2606<\/value> \r\n<\/field>   \r\n<field id=\"prodNo\">    \r\n<value>32456240<\/value>\r\n<\/field>\r\n<field id=\"price\">      \r\n<value>$30.00<\/value>\r\n<\/field>\r\n<\/tool>\r\n<\/pre>\n

\u63a5\u7740\uff0c\u8bf7\u770b\u4e0b\u9762\u7684\u6837\u5f0f\u8868\uff08\"tool.xsl\"\uff09\uff1a<\/p>\n

\r\n<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<xsl:stylesheet version=\"1.0\"\r\nxmlns:xsl=\"http:\/\/www.w3.org\/1999\/XSL\/Transform\">\r\n<xsl:template match=\"\/\">\r\n<html>\r\n<body>\r\n<form method=\"post\" action=\"edittool.html\">\r\n<h2>Tool Information (edit):<\/h2>\r\n<table border=\"0\">\r\n<xsl:for-each select=\"tool\/field\">\r\n<tr>  \r\n<td><xsl:value-of select=\"@id\"\/><\/td>\r\n<td>    \r\n<input type=\"text\">\r\n<xsl:attribute name=\"id\">\r\n<xsl:value-of select=\"@id\" \/>\r\n<\/xsl:attribute>    \r\n<xsl:attribute name=\"name\">\r\n<xsl:value-of select=\"@id\" \/>\r\n<\/xsl:attribute>    \r\n<xsl:attribute name=\"value\">\r\n<xsl:value-of select=\"value\" \/>\r\n<\/xsl:attribute>    \r\n<\/input>   \r\n<\/td>  \r\n<\/tr>  \r\n<\/xsl:for-each> \r\n<\/table> \r\n<br \/>\r\n<input type=\"submit\" id=\"btn_sub\" name=\"btn_sub\" value=\"Submit\" \/>\r\n<input type=\"reset\" id=\"btn_res\" name=\"btn_res\" value=\"Reset\" \/> \r\n<\/form>\r\n<\/body>\r\n<\/html>\r\n<\/xsl:template>\r\n<\/xsl:stylesheet>\r\n<\/pre>\n

\u4e0a\u9762\u8fd9\u4e2a XSL \u6587\u4ef6\u4f1a\u5faa\u73af\u904d\u5386 XML \u6587\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u5e76\u4e3a\u6bcf\u4e2a XML \"field\" \u5143\u7d20\u521b\u5efa\u4e00\u4e2a\u8f93\u5165\u57df\u3002XML \"field\" \u5143\u7d20\u7684 \"id\" \u5c5e\u6027\u7684\u503c\u88ab\u6dfb\u52a0\u5230\u6bcf\u4e2a HTML \u8f93\u5165\u57df\u7684 \"id\" \u548c \"name\" \u5c5e\u6027\u3002\u6bcf\u4e2a XML \"value\" \u5143\u7d20\u7684\u503c\u88ab\u6dfb\u52a0\u5230\u6bcf\u4e2a HTML \u8f93\u5165\u57df\u7684 \"value\" \u5c5e\u6027\u3002\u7ed3\u679c\u662f\uff0c\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u5305\u542b XML \u6587\u4ef6\u4e2d\u503c\u7684\u53ef\u7f16\u8f91\u7684 HTML \u8868\u5355\u3002<\/p>\n

\u7136\u540e\uff0c\u6211\u4eec\u8fd8\u6709\u7b2c\u4e8c\u4e2a\u6837\u5f0f\u8868\uff1a\"tool_updated.xsl\"\u3002\u8fd9\u4e2a XSL \u6587\u4ef6\u4f1a\u88ab\u7528\u6765\u663e\u793a\u5df2\u66f4\u65b0\u7684 XML \u6570\u636e\u3002\u8fd9\u4e2a\u6837\u5f0f\u8868\u4e0d\u4f1a\u8f93\u51fa\u53ef\u7f16\u8f91 HTML \u8868\u5355\uff0c\u800c\u662f\u4e00\u4e2a\u9759\u6001\u7684 HTML \u8868\u683c\uff1a<\/p>\n

\r\n<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<xsl:stylesheet version=\"1.0\"\r\nxmlns:xsl=\"http:\/\/www.w3.org\/1999\/XSL\/Transform\">\r\n<xsl:template match=\"\/\"> \r\n<html> \r\n<body> \r\n<h2>Updated Tool Information:<\/h2> \r\n<table border=\"1\">   \r\n<xsl:for-each select=\"tool\/field\">\r\n<tr>     \r\n<td><xsl:value-of select=\"@id\" \/><\/td>   \r\n<td><xsl:value-of select=\"value\" \/><\/td>  \r\n<\/tr>   \r\n<\/xsl:for-each>\r\n<\/table> \r\n<\/body>\r\n<\/html>\r\n<\/xsl:template>\r\n<\/xsl:stylesheet>\r\n<\/pre>\n
ASP \u6587\u4ef6<\/strong><\/div>\n

\u5728\u4e0a\u9762 \"tool.xsl\" \u6587\u4ef6\u4e2d\uff0cHTML \u8868\u5355\u7684 action \u5c5e\u6027\u7684\u503c\u662f \"edittool.asp\" \u3002<\/p>\n

\"edittool.asp\" \u9875\u9762\u5305\u542b\u4e24\u4e2a\u51fd\u6570\uff1aloadFile() \u51fd\u6570\u8f7d\u5165\u5e76\u8f6c\u6362 XML \u6587\u4ef6\uff0cupdateFile() \u51fd\u6570\u66f4\u65b0 XML \u6587\u4ef6\uff1a<\/p>\n

\r\n<%
\r\nfunction loadFile(xmlfile,xslfile)\r\nDim xmlDoc,xslDoc
'Load XML file\r\nset xmlDoc = Server.CreateObject(\"Microsoft.XMLDOM\")\r\nxmlDoc.async = false\r\nxmlDoc.load(xmlfile)
'Load XSL file\r\nset xslDoc = Server.CreateObject(\"Microsoft.XMLDOM\")\r\nxslDoc.async = false\r\nxslDoc.load(xslfile)
'Transform file\r\nResponse.Write(xmlDoc.transformNode(xslDoc))\r\nend function\r\nfunction updateFile(xmlfile)\r\nDim xmlDoc,rootEl,f\r\nDim i
'Load XML file\r\nset xmlDoc = Server.CreateObject(\"Microsoft.XMLDOM\")\r\nxmlDoc.async = false\r\nxmlDoc.load(xmlfile)\r\n'Set the rootEl variable equal to the root element\r\nSet rootEl = xmlDoc.documentElement\r\n'Loop through the form collection\r\nfor i = 1 To Request.Form.Count \r\n'Eliminate button elements in the form\r\nif instr(1,Request.Form.Key(i),\"btn_\")=0 then \r\n'The selectSingleNode method queries the XML file for a single node\r\n'that matches a query. This query requests the value element that is \r\n'the child of a field element that has an id attribute which matches \r\n'the current key value in the Form Collection. When there is a match - \r\n'set the text property equal to the value of the current field in the\r\n'Form Collection.\r\nset f = rootEl.selectSingleNode(\"field[@id='\" & _\r\nRequest.Form.Key(i) & \"']\/value\") \r\nf.Text = Request.Form(i)\r\nend if\r\nnext\r\n'Save the modified XML file\r\nxmlDoc.save xmlfile\r\n'Release all object references\r\nset xmlDoc=nothing\r\nset rootEl=nothing\r\nset f=nothing\r\n'Load the modified XML file with a style sheet that\r\n'allows the client to see the edited information\r\nloadFile xmlfile,server.MapPath(\"tool_updated.xsl\")\r\nend function\r\n'If the form has been submitted update the\r\n'XML file and display result - if not,\r\n'transform the XML file for editing\r\nif Request.Form(\"btn_sub\")=\"\" then \r\nloadFile server.MapPath(\"tool.xml\"),server.MapPath(\"tool.xsl\")\r\nelse\r\nupdateFile server.MapPath(\"tool.xml\")\r\nend if\r\n%>\r\n<\/pre>\n

\u6ce8\u610f\uff1a\u6211\u4eec\u6b63\u5728\u8f6c\u6362\u5e76\u66f4\u65b0\u4f4d\u4e8e\u670d\u52a1\u5668\u4e0a\u7684 XML \u6587\u4ef6\u3002\u8fd9\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5ba2\u6237\u7aef\u4ec5\u80fd\u83b7\u5f97\u4ece\u670d\u52a1\u5668\u8fd4\u56de\u7684 HTML - \u800c HTML \u53ef\u8fd0\u884c\u4e8e\u4efb\u4f55\u6d4f\u89c8\u5668\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u73b0\u5728\uff0c\u6211\u4eec\u4f1a\u4e3a\u60a8\u5c55\u793a\u5982\u4f55\u6253\u5f00\u3001\u7f16\u8f91\u53ca\u4fdd\u5b58\u5b58\u50a8\u4e8e\u670d\u52a1\u5668\u4e0a\u7684 XML \u6587\u4ef6\u3002 \u6211\u4eec\u5c06\u4f7f\u7528 XSL \u628a XML \u6587\u6863 […]<\/p>\n","protected":false},"author":1481,"featured_media":248397,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-248395","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/248395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=248395"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/248395\/revisions"}],"predecessor-version":[{"id":248400,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/248395\/revisions\/248400"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/248397"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=248395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=248395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=248395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}