0

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)'ソースファイルと'変換ファイルを表す2つの文字列を作成します。これらの値は、さまざまなメソッド(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に。

事前にt​​hx

4

1 に答える 1

2

私はあなたが単に欲しいと思います

Using sw As New StringWriter()
  serializer.SetOutputWriter(sw)
  transformer.Run(serializer)
  Literal1.Text = sw.ToString()
End Using
于 2012-07-02T10:03:56.930 に答える