{"id":248389,"date":"2022-08-02T10:28:52","date_gmt":"2022-08-02T02:28:52","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=248389"},"modified":"2022-07-22T11:29:14","modified_gmt":"2022-07-22T03:29:14","slug":"server-side-overview","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/server-side-overview.html","title":{"rendered":"XSLT – \u670d\u52a1\u5668\u7aef\u6982\u8ff0"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u7531\u4e8e\u5e76\u975e\u6240\u6709\u7684\u6d4f\u89c8\u5668\u90fd\u652f\u6301 XSLT\uff0c\u53e6\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u662f\u5728\u670d\u52a1\u5668\u4e0a\u5b8c\u6210 XML \u81f3 XHTML \u7684\u8f6c\u5316\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u8de8\u6d4f\u89c8\u5668\u89e3\u51b3\u65b9\u6848<\/strong><\/div>\n

\u5728\u524d\u9762\u7684\u7ae0\u8282\uff0c\u6211\u4eec\u8bb2\u89e3\u8fc7\u5982\u4f55\u5728\u6d4f\u89c8\u5668\u4e2d\u4f7f\u7528 XSLT \u6765\u5b8c\u6210 XML \u5230 XHTML \u7684\u8f6c\u5316\u3002\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u6bb5\u4f7f\u7528 XML \u89e3\u6790\u5668\u6765\u8fdb\u884c\u8f6c\u6362\u7684 JavaScript\u3002JavaScript \u89e3\u51b3\u65b9\u6848\u65e0\u6cd5\u5de5\u4f5c\u4e8e\u6ca1\u6709 XML \u89e3\u6790\u5668\u7684\u6d4f\u89c8\u5668\u3002
\n\u4e3a\u4e86\u8ba9 XML \u6570\u636e\u9002\u7528\u4e8e\u4efb\u4f55\u7c7b\u578b\u7684\u6d4f\u89c8\u5668\uff0c\u6211\u4eec\u5fc5\u987b\u5728\u670d\u52a1\u5668\u4e0a\u5bf9 XML \u6587\u6863\u8fdb\u884c\u8f6c\u6362\uff0c\u7136\u540e\u5c06\u5176\u4f5c\u4e3a XHMTL \u53d1\u9001\u56de\u6d4f\u89c8\u5668\u3002<\/p>\n

\u8fd9\u662f XSLT \u7684\u53e6\u4e00\u4e2a\u4f18\u70b9\u3002XSLT \u7684\u8bbe\u8ba1\u76ee\u6807\u4e4b\u4e00\u662f\u4f7f\u6570\u636e\u5728\u670d\u52a1\u5668\u4e0a\u4ece\u4e00\u79cd\u683c\u5f0f\u8f6c\u6362\u5230\u53e6\u4e00\u79cd\u683c\u5f0f\u6210\u4e3a\u53ef\u80fd\uff0c\u5e76\u5411\u6240\u6709\u7c7b\u578b\u7684\u6d4f\u89c8\u5668\u8fd4\u56de\u53ef\u8bfb\u7684\u6570\u636e\u3002<\/p>\n

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

\u8bf7\u770b\u8fd9\u4e2a\u5728\u524d\u9762\u7684\u7ae0\u8282\u5df2\u5c55\u793a\u8fc7\u7684 XML \u6587\u6863\uff1a<\/p>\n

<?<\/span>xml version<\/span>=<\/span>\"1.0\"<\/span> encoding<\/span>=<\/span>\"UTF-8\"<\/span>?><\/span>\r\n<\/span><catalog><\/span>\r\n  <\/span><cd><\/span>\r\n    <\/span><title><\/span>Empire Burlesque<\/span><\/title><\/span>\r\n    <\/span><artist><\/span>Bob Dylan<\/span><\/artist><\/span>\r\n    <\/span><country><\/span>USA<\/span><\/country><\/span>\r\n    <\/span><company><\/span>Columbia<\/span><\/company><\/span>\r\n    <\/span><price><\/span>10.90<\/span><\/price><\/span>\r\n    <\/span><year><\/span>1985<\/span><\/year><\/span>\r\n  <\/span><\/cd><\/span>\r\n.\r\n.\r\n<\/span><\/catalog><\/span><\/pre>\n

\u4ee5\u53ca\u9644\u968f\u7684 XSL \u6837\u5f0f\u8868\uff1a<\/p>\n

<?<\/span>xml version<\/span>=<\/span>\"1.0\"<\/span> encoding<\/span>=<\/span>\"UTF-8\"<\/span>?><\/span>\r\n<\/span><xsl:stylesheet<\/span> <\/span>version<\/span>=<\/span>\"1.0\"<\/span>\r\n<\/span>xmlns:xsl<\/span>=<\/span>\"http:\/\/www.w3.org\/1999\/XSL\/Transform\"<\/span>><\/span>\r\n\r\n<\/span><xsl:template<\/span> <\/span>match<\/span>=<\/span>\"\/\"<\/span>><\/span>\r\n  <\/span><h2><\/span>My CD Collection<\/span><\/h2><\/span>\r\n  <\/span><table<\/span> <\/span>border<\/span>=<\/span>\"1\"<\/span>><\/span>\r\n    <\/span><tr<\/span> <\/span>bgcolor<\/span>=<\/span>\"#9acd32\"<\/span>><\/span>\r\n      <\/span><th<\/span> <\/span>style<\/span>=<\/span>\"<\/span>text<\/span>-<\/span>align<\/span>:<\/span>left<\/span>\"<\/span>><\/span>Title<\/span><\/th><\/span>\r\n      <\/span><th<\/span> <\/span>style<\/span>=<\/span>\"<\/span>text<\/span>-<\/span>align<\/span>:<\/span>left<\/span>\"<\/span>><\/span>Artist<\/span><\/th><\/span>\r\n    <\/span><\/tr><\/span>\r\n    <\/span><xsl:for-each<\/span> <\/span>select<\/span>=<\/span>\"catalog\/cd\"<\/span>><\/span>\r\n    <\/span><tr><\/span>\r\n      <\/span><td><xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"title\"<\/span> <\/span>\/><\/td><\/span>\r\n      <\/span><td><xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"artist\"<\/span> <\/span>\/><\/td><\/span>\r\n    <\/span><\/tr><\/span>\r\n    <\/span><\/xsl:for-each><\/span>\r\n  <\/span><\/table><\/span>\r\n<\/span><\/xsl:template><\/span>\r\n\r\n<\/span><\/xsl:stylesheet><\/span><\/pre>\n

\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e2a XML \u6587\u4ef6\u6ca1\u6709\u5305\u542b\u5bf9 XSL \u6587\u4ef6\u7684\u5f15\u7528\u3002<\/p>\n

\u91cd\u8981\u4e8b\u9879\uff1a\u4e0a\u9762\u8fd9\u53e5\u8bdd\u610f\u5473\u7740\uff0cXML \u6587\u4ef6\u53ef\u4f7f\u7528\u591a\u4e2a\u4e0d\u540c\u7684 XSL \u6837\u5f0f\u8868\u6765\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n

\u5728\u670d\u52a1\u5668\u628a XML \u8f6c\u6362\u4e3a XHTML<\/strong><\/div>\n

\u8fd9\u662f\u7528\u4e8e\u5728\u670d\u52a1\u5668\u4e0a\u628a XML \u6587\u4ef6\u8f6c\u6362\u4e3a XHTML \u7684\u6e90\u4ee3\u7801\uff1a<\/p>\n

\u4f7f\u7528 PHP \u4ee3\u7801\u8f6c\u6362<\/strong><\/span><\/div>\n
<?<\/span>php\r\n<\/span>\/\/ \u8f7d\u5165 XML \u6587\u4ef6<\/span>\r\n$xml <\/span>=<\/span> <\/span>new<\/span> <\/span>DOMDocument<\/span>;<\/span>\r\n$xml<\/span>-><\/span>load<\/span>(<\/span>'cdcatalog.xml'<\/span>);<\/span>\r\n\r\n<\/span>\/\/ \u8f7d\u5165 XSL \u6587\u4ef6<\/span>\r\n$xsl <\/span>=<\/span> <\/span>new<\/span> <\/span>DOMDocument<\/span>;<\/span>\r\n$xsl<\/span>-><\/span>load<\/span>(<\/span>'cdcatalog.xsl'<\/span>);<\/span>\r\n\r\n<\/span>\/\/ \u8bbe\u7f6e\u8f6c\u6362<\/span>\r\n$proc <\/span>=<\/span> <\/span>new<\/span> <\/span>XSLTProcessor<\/span>;<\/span>\r\n\r\n<\/span>\/\/ \u6dfb\u52a0 xsl \u89c4\u5219<\/span>\r\n$proc<\/span>-><\/span>importStyleSheet<\/span>(<\/span>$xsl<\/span>);<\/span>\r\n\r\necho $proc<\/span>-><\/span>transformToXML<\/span>(<\/span>$xml<\/span>);<\/span>\r\n<\/span>?><\/span><\/pre>\n
\u4f7f\u7528 ASP \u4ee3\u7801\u8f6c\u6362<\/strong><\/span><\/div>\n
<%<\/span>\r\n<\/span>'\u8f7d\u5165 XML \u6587\u4ef6\r\nset xml = Server.CreateObject(\"Microsoft.XMLDOM\")\r\nxml.async = false\r\nxml.load(Server.MapPath(\"cdcatalog.xml\"))\r\n\r\n'<\/span>\u8f7d\u5165<\/span> XSL <\/span>\u6587\u4ef6<\/span>\r\n<\/span>set<\/span> xsl <\/span>=<\/span> <\/span>Server<\/span>.<\/span>CreateObject<\/span>(<\/span>\"Microsoft.XMLDOM\"<\/span>)<\/span>\r\nxsl<\/span>.<\/span>async <\/span>=<\/span> <\/span>false<\/span>\r\nxsl<\/span>.<\/span>load<\/span>(<\/span>Server<\/span>.<\/span>MapPath<\/span>(<\/span>\"cdcatalog.xsl\"<\/span>))<\/span>\r\n\r\n<\/span>'\u8f6c\u6362\u6587\u4ef6\r\nResponse.Write(xml.transformNode(xsl))\r\n<\/span>%><\/span><\/pre>\n

\u7b2c\u4e00\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u5fae\u8f6f\u7684 XML \u89e3\u6790\u5668\uff08XMLDOM\uff09\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u5e76\u628a XML \u6587\u4ef6\u8f7d\u5165\u4e86\u5185\u5b58\u3002\u7b2c\u4e8c\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u89e3\u6790\u5668\u7684\u53e6\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u5e76\u628a\u8fd9\u4e2a XSL \u6587\u4ef6\u8f7d\u5165\u4e86\u5185\u5b58\u3002\u6700\u540e\u4e00\u884c\u4ee3\u7801\u4f7f\u7528 XSL \u6587\u6863\u8f6c\u6362\u4e86 XML \u6587\u6863\uff0c\u5e76\u628a\u7ed3\u679c\u4f5c\u4e3a XHTML \u53d1\u9001\u5230\u60a8\u7684\u6d4f\u89c8\u5668\u3002\u592a\u597d\u4e86\uff01<\/p>\n

\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u524d\u9762\u7684\u7ae0\u8282\uff0c\u6211\u4eec\u8bb2\u89e3\u8fc7\u5982\u4f55\u5728\u6d4f\u89c8\u5668\u4e2d\u4f7f\u7528 XSLT \u6765\u5b8c\u6210 XML \u5230 XHTML \u7684\u8f6c\u5316\u3002\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u6bb5\u4f7f […]<\/p>\n","protected":false},"author":1481,"featured_media":248391,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-248389","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\/248389","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=248389"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/248389\/revisions"}],"predecessor-version":[{"id":248394,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/248389\/revisions\/248394"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/248391"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=248389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=248389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=248389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}