XSLT转换的ASP.NET问题

时间:2011-06-14 10:03:34

标签: asp.net xml xslt

我需要以下问题的帮助。我解析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"/>

2 个答案:

答案 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)

看看这个:

XML / XSLT Transformation

您必须在ASPX页面上使用XML Server Control,然后设置XSLT转换