使用 XSLT 样式表转换 XML 数据

    技术2022-05-11  119

     

    .net 的 System.Xml.Xsl 命名空间提供了强大了转换支持,可将 XML 数据或文件与样式表合并,如下代码:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  Dim X As New System.Xml.XmlTextReader(Server.MapPath("test.xml"))  Dim S As New System.Xml.Xsl.XslCompiledTransform  S.Load(Server.MapPath("style.xsl"))

      Dim W As New System.Xml.XmlTextWriter(Response.OutputStream, System.Text.UTF8Encoding.UTF8)  S.Transform(X, W)  X.Close()

      W.Close()

      Response.End() End Sub 

     

    一般做网站时,美工人员做好界面,然后由程序员将程序套进去,比较麻烦,而且做好的界面一般都要修改才能套,费时费力。如果使用这种方式的话,程序员只需要将数据按约定的格式生成 XML 就行了,美工人员直接将界面做成 XSL 文件,最终将两种文件合并即可。


    最新回复(0)