我需要以下问题的帮助。我解析XML并进行XSLT转换。 Stylus Studio一切都很好。但是使用ASP.NET我无法解析和输出。
min.aspx.vb
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.IO
Partial Class Poseidon_min
Inherits System.Web.UI.Page
Protected Sub Literal1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Literal1.PreRender
Dim strXSLTFile As String = "http://www.kiris-alinda.de/Poseidon/Hotelangebote.xslt"
Dim strXMLFile As String = "http://www.kiris-alinda.de/Poseidon/PosXMLReq/PosXMLReqSearch.php?htc=AYTLIND"
Dim reader As XmlReader = XmlReader.Create(strXMLFile)
Dim objXSLTransform As New XslCompiledTransform()
objXSLTransform.Load(strXSLTFile)
Dim htmlOutput As New StringBuilder()
'Dim htmlWriter As TextWriter = New StringWriter(htmlOutput)
'objXSLTransform.Transform(reader, Nothing, htmlWriter)
Me.Literal1.Text = htmlOutput.ToString()
reader.Close()
End Sub
End Class
为什么无法从ASP.NET中的XSLT输出<xsl:value-of select="PosXmlResponse/search/date/@min"/>
?
答案 0 :(得分:0)
我使用此代码:
Public Shared Function Transform(xml As String, xsl As String, argsList As XsltArgumentList) As String
Dim selectedXml As XDocument = XDocument.Parse(xml)
Dim xmlTransform As New XslCompiledTransform()
Dim htmlOutput As New StringBuilder()
Dim writer As XmlWriter = XmlWriter.Create(htmlOutput)
xmlTransform.Load(New XmlTextReader(New StringReader(xsl)))
xmlTransform.Transform(selectedXml.CreateReader(), argsList, writer)
Return htmlOutput.ToString()
End Function
答案 1 :(得分:0)