saxon.net write преобразовал xslt в литерал

нужна помощь с saxon.net.

Может ли кто-нибудь сказать мне, как вывести преобразованный xslt xlm в литерал asp.net?

' NOTE: Saxon now uses System.Xml internally on the .NET platform.

' Мы могли бы импортировать его и использовать любые производные от него классы, методы и т. д., ' но в этом примере мы будем использовать FileStream как для исходного ' файла, так и для файлов преобразования, а Saxon позаботится обо всем оттуда, ', поэтому нет необходимости импортировать System.Xml для этого конкретного примера. Private Sub Page_Load(sender As [Object], e As EventArgs) ' Создайте две строки, представляющие исходный файл и ' файл преобразований. Эти значения могут быть установлены с использованием ' различных методов (например, QueryString), но сейчас ' мы не будем усложнять и жестко закодируем эти значения. Dim sourceUri As [String] = Server.MapPath("beispiel1.xml") Dim xsltUri As [String] = Server.MapPath("beispiel1.xslt")

' The new Saxon engine for the .NET platform allows the
' ability to pass in a Stream instance directly.
' Given that the Stream class implements IDisposable, we
' can use the 'using' keyword/codeblock to ensure that
' our resources are properly cleaned up, freeing up
' valuable system resources in the process.
' [UPDATE: Check that.  This really should read
' close all of the file streams we opened automagically.
' While its true we're cleaning up system resources
' It's not like theres really a choice.  One way
' or another the stream needs to be closed, this
' Just does this for us so we don't have to worry about it.
Using sXml As FileStream = File.OpenRead(sourceUri)
    ' We need to do this for each Stream that we pass in for processing.
    Using sXsl As FileStream = File.OpenRead(xsltUri)
        ' Now we simply create a Processor instance.
        Dim processor As New Processor()

        ' Load the source document into a DocumentBuilder
        Dim builder As DocumentBuilder = processor.NewDocumentBuilder()

        ' Because we have created the DocumentBuilder with a file stream
        ' we need to set the BaseUri manually, as this information is no
        ' longer available to the Saxon internals when a Stream, regardless
        ' of what the source of this Stream happens to be, is used for creating
        ' the DocumentBuilder instance.  With this in mind, we need to create
        ' an instance of a Uri using the sourceUri we created above.
        Dim sUri As New Uri(sourceUri)

        ' Now set the baseUri for the builder we created.
        builder.BaseUri = sUri

        ' Instantiating the Build method of the DocumentBuilder class will then
        ' provide the proper XdmNode type for processing.
        Dim input As XdmNode = builder.Build(sXml)

        ' Create a transformer for the transformation file, compiling and loading this
        ' file using the NewXsltCompiler method of the Saxon.Api namespace.
        Dim transformer As XsltTransformer = processor.NewXsltCompiler().Compile(sXsl).Load()

        ' Set the root node of the source document to be the initial context node.
        transformer.InitialContextNode = input

        ' Create a serializer
        Dim serializer As New Serializer()

        ' Set the serializer to write the transformation output directly
        ' to ASP.NET's Response.Output stream.
        serializer.SetOutputWriter(Response.Output)

        ' Run the transformation.
        transformer.Run(serializer)

        ' and we're done. :)
        Literal1.Text = "xslt xml transformed output here"
    End Using
End Using

Конец сабвуфера

Я не хочу писать это в поток response.output. Но в Literal1.Text.

спасибо заранее


person user168507    schedule 02.07.2012    source источник


Ответы (1)


Я думаю, ты просто хочешь

Using sw As New StringWriter()
  serializer.SetOutputWriter(sw)
  transformer.Run(serializer)
  Literal1.Text = sw.ToString()
End Using
person Martin Honnen    schedule 02.07.2012