首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

怎样将一个XML转换格式为另一个XML(用XSL)解决思路

2012-03-06 
怎样将一个XML转换格式为另一个XML(用XSL)如:?xmlversion1.0encodingUTF-8 ?ROOTBookname XML

怎样将一个XML转换格式为另一个XML(用XSL)
如:
<?xml   version   =   '1.0 '   encoding   =   'UTF-8 '?>
<ROOT>
<Book>
  <name> XML </name>
  <price> 20 </price>
</Book>
<ROOT>

目标格式:
<?xml   version   = '1.0 '   encoding   =   'UTF-8 '?>
<Books>
<Book   name= "XML "   price= "20 "/>
<Books>

[解决办法]
<%
Set xslt = CreateObject( "Msxml2.XSLTemplate ")
Set xslDoc = CreateObject( "Msxml2.FreeThreadedDOMDocument ")
xslDoc.async = False
xslDoc.resolveExternals = False
xslDoc.Load Server.MapPath( "test0701.xsl ")


If (xslDoc.parseError.errorCode <> 0) Then
Set myErr = xslDoc.parseError
Response.Write "You have error " & myErr.reason
Else
Set xslt.stylesheet = xslDoc
Set xmlDoc = CreateObject( "Msxml2.DOMDocument ")
xmlDoc.async = False
xmlDoc.resolveExternals = False
xmlDoc.Load Server.MapPath( "test0701.xml ")
If (xmlDoc.parseError.errorCode <> 0) Then
Set myErr = xmlDoc.parseError
Response.Write "You have error " & myErr.reason
Else
Set xslProc = xslt.createProcessor()
xslProc.input = xmlDoc
xslProc.Transform
Response.Write Server.HTMLEncode(xslProc.output)
End If
End If
%>

热点排行