如何使用XSL创建XML XML? [英] How create XML from XML using XSL?
本文介绍了如何使用XSL创建XML XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从XML使用XSL创建XML?
How create XML from XML using XSL ?
我尝试这样的..但我没有得到的结果。
I try like this.. but i not get a result
的test.xml
<Address>
<name> Alex</name>
<lastname>Mathew</lastname>
</Address>
Test.xsl
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>
我需要出去把这样的
I need out put like this
<Address>
<FirstName> Alex</FirstName>
<LastName>Mathew</LastName>
</Address>
我试着在我的ASP页面转换(TEST.ASP)
I try to convert in my asp page (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帮我解决这个问题。
Plz help me solve this problem
推荐答案
您可能还需要在样式表中增加一个输出指令:
You might also want to add an output directive in your stylesheet:
<?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声明:
This causes the output to have a leading xml declaration:
<?xml version="1.0" ?>
这篇关于如何使用XSL创建XML XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文