如何使用XSL从XML创建XML?
我尝试这样..但我得不到结果
的test.xml
<Address> <name> Alex</name> <lastname>Mathew</lastname> </Address>
Test.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="/"> <Address> <FirstName><xsl:value-of select="name" /></FirstName> <LastName><xsl:value-of select="lastname" /></LastName> </Address> </xsl:template> </xsl:stylesheet>
我需要这样做
<Address> <FirstName> Alex</FirstName> <LastName>Mathew</LastName> </Address>
我尝试在我的asp页面中转换(test.asp)
<% 'Load XML set xml = Server.CreateObject("Microsoft.XMLDOM") xml.async = false xml.load(Server.MapPath("Test.xml")) 'Load XSL set xsl = Server.CreateObject("Microsoft.XMLDOM") xsl.async = false xsl.load(Server.MapPath("Test.xsl")) 'Response.Write(xml.transformNode(xsl)) 'Response.ContentType = "text/plain; charset=UTF-8" Set doc = Server.CreateObject("Msxml2.DOMDocument.3.0") doc.async = False doc.loadXML(xml.transformNode(xsl)) response.write xml.transformNode(xsl) response.write doc.getElementsByTagName("FirstName").item(0).text %>
Plz帮我解决了这个问题
您可能还想在样式表中添加输出指令:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/Address"> <Address> <FirstName><xsl:value-of select="name" /></FirstName> <LastName><xsl:value-of select="lastname" /></LastName> </Address> </xsl:template> </xsl:stylesheet>
这会导致输出具有前导xml声明:
<?xml version="1.0" ?>