This site uses cookies to deliver our services. By using this site, you acknowledge that you have read and understand our Cookie and Privacy policy. Your use of Kontext website is subject to this policy. Allow Cookies and Dismiss

Javascript + Xslt 解析Xml为Html的方法

455 views 0 comments last modified about 9 years ago Raymond Tang

In this page



下面的代码摘自我的最近的一个项目中的,整个项目页面展示基本都用Xslt来解析XML数据, 在后台直接通过XsltTransform类,而在前台一些页面,则采用了Javascript来实现

function openBdp(bdpID,name)
      var xslt = new ActiveXObject("Msxml2.XSLTemplate.3.0");
      var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");
      var xmlDom =new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0");
      xslDoc.async = false;
      xmlDom.async = false;
      xslt.stylesheet = xslDoc;
      var xslProc = xslt.createProcessor();


xslProc.addParameter("bdpTypeName", name);

      }//end function


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
   <xsl:output encoding="utf-8" method="xml" omit-xml-declaration = "yes" indent="yes"/>
   <xsl:param name="rootPath"/>
   <xsl:param name="bdpTypeName"/>
   <xsl:param name="isDevice"/>
   <xsl:param name="isRight"/>
   <xsl:param name="showBtn"/>
   <xsl:template match="/">
      <xsl:if test="$isDevice='1'">
          ...         <br/>
      <xsl:call-template name="showDealInfo"/>

   <xsl:template name="showDealInfo">
      <xsl:variable name="node" select="DealInfo/DealType[@Name=$bdpTypeName]"/>
      <table class="listTable" cellspacing="0" cellpadding="3" rules="all" border="1" id="DataGridBDPDetails" style="width:100%;border-collapse:collapse;">
         <tr class="header">
         <xsl:for-each select="$node/DealDetail">
            <xsl:element name="tr">
               <xsl:if test="position() mod 2 =0">
                  <xsl:attribute name="style">background-color:#D2FFA6</xsl:attribute>
                  <xsl:value-of select="$bdpTypeName"/>
                  <xsl:value-of select="TypeName"/>
                  <xsl:value-of select="TestData"/>
                  <xsl:value-of select="StandardValue"/>
               <td style="color:red;font-weight:bold">
                  <xsl:value-of select="Conclusion"/>
      <xsl:if test="$showBtn='1'">
         <div style="text-align: center;margin:10px 0px">
            <input class="button2d" onclick="window.close()" type="button" value=" 关 闭 " />

   <xsl:template name="blank">
      <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>


<DealInfo><DealType Name="333" ID="101" BDPID="" BDP_IsRight="1"/>

<DealType Name="3333" ID="102" BDPID="" BDP_IsRight="1"/>




Related pages

Issue - Unable to get property 'apply' of undefined or null reference occurred in Angular 4.*, VS2017 15.3, ASP.NET Core 2.0

6815 views   10 comments last modified about 2 years ago

Issue Context After installed Visual Studio 2017 15.3 preview and .net core 2.0 preview SDK, I upgraded one of my existing core project to 2.0. The project was created using ‘dotnet new angular’ SPA template.&nbsp; I also upgraded all the client app packages to the latest. For exa...

View detail

[Link] Build SPA on ASP.NET Core with JavaScript Services

455 views   0 comments last modified about 2 years ago

Great introduction about JavaScriptServices ( JavaScriptServices GitHub repository ): Microsoft.AspNetCore.SpaTemplates plugs into dotnet new , providing project templates for Angular 2, Aurelia, Knockout...

View detail

input submit input text css的写法

111 views   0 comments last modified about 10 years ago


View detail


271 views   0 comments last modified about 9 years ago


View detail


1392 views   0 comments last modified about 7 years ago


View detail


340 views   0 comments last modified about 9 years ago


View detail

Add comment

Please login first to add comments.  Log in New user?  Register

Comments (0)

No comments yet.