2012-07-02 1 views
0

saxon.net에 대한 도움이 필요합니다.saxon.net 리터럴로 변환 된 xslt 쓰기

아무도 내가 asp.net 리터럴로 xslt 변형 된 xlm을 출력하는 방법을 말해 줄 수 있습니까?

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

'우리는 그것을 가져 파생 클래스, 방법 중 하나를 사용, 등, 은 수'하지만이 예에서 우리는 소스 '및 변환 파일을 모두 FileStream 객체를 사용하는 것, 그리고 색슨 거기에서 물건을 돌보는 것입니다, '이 특별한 예제를 위해 System.Xml을 가져올 필요가 없습니다. Private Sub Page_Load (보낸 사람 : [Object], e EventArgs) '원본 파일을 나타내는 두 개의 문자열과 '변환 파일을 만듭니다. 이 값은 '다양한 검색어 (예 : QueryString)를 사용하여 설정할 수 있지만 지금은 '으로 단순하게 유지하고 값을 하드 코딩합니다. 어둡게 sourceUri 같이 문자열 =는 Server.MapPath ("beispiel1.xml") 어둡게 xsltUri 같이 문자열 =는 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 

최종 서브

I 그것을 response.output 스트림에 쓰고 싶지는 않습니다. 그러나 Literal1.Text. 사전

답변

2

에서

들으 난 당신이 단순히

Using sw As New StringWriter() 
    serializer.SetOutputWriter(sw) 
    transformer.Run(serializer) 
    Literal1.Text = sw.ToString() 
End Using 
+0

들으 싶은 생각은, 내가 원하는 것을 단순히 이잖아 – user168507