XSLT - 将节点值呈现为HTML UI(不显示未转义的HTML脚本)

时间:2015-08-24 11:47:41

标签: c# html xslt escaping webbrowser-control

环境 - Dot Net 4.0,C#,XSLT,IE11,WebBrowser控件

我有一个XSLT,它处理一个包含转义HTML内容的节点......

"<b>Hellow World</b>"

我有一个WebBrowser控件,用于显示XSLT的转换后的HTML 我使用了<xsl:value-of .. disable-output-escaping="yes">它显示了带有实际<b> & </b>标记的HTML文本的未转义值。

我想呈现粗体文字,而不是显示制作粗体标签的未转义HTML脚本。

下面的行显示未经验证的HTML代码,而我实际上想显示/转发HTML用户界面

<xsl:value-of select="orderDetails/HTMLData" disable-output-escaping="yes"/>

修改

我正在使用C#代码应用XSLT转换,并在IE11 / Chrome上的页面上显示输出。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="assetTypeText" ></xsl:param>
  <xsl:template match="/">

    <table border="1" class="mainTable">

      <!--Header-->
      <tr>
        <td class="tdMainHeader">
          <xsl:value-of select="$assetTypeText" /> - <xsl:value-of select="//order/execOrderID/entityOID"></xsl:value-of>
        </td>
      </tr>

      <!--Client Information-->
      <tr class="trMain">
        <table class="InnerMainTable" >
          <tr>
            <td class="tdH2" colspan="2" >Client Information:</td>
          </tr>
          <tr>
            <td colspan="2" class="tdH4">
              <table align="left">
                <tr>
                  <td class="tdInnerTableHeader">DESI</td>
                  <td class="tdInnerTableHeader">ACCOUNT</td>
                 <td class="tdInnerTableHeader">Markup Type</td>
                  <td class="tdInnerTableHeader">Markup</td>
                </tr>
                <xsl:for-each select="//allocation">
                  <tr>
                    <td class="tdInnerTableValue" style="width:20%">
                      <xsl:value-of select="clientDetails/clientID" />
                    </td>
                    <td class="tdInnerTableValue" style="width:20%">
                      <xsl:value-of select="clientDetails/accountID" />
                    </td>
                    <td class="tdInnerTableValue" style="width:20%">
                      <xsl:apply-templates select="charges/charge/chargeFormula" mode="enum"/>
                    </td>
                    <td class="tdInnerTableValue" style="width:20%">
                      <xsl:value-of select="charges/charge/chargeRate" />
                    </td>
                  </tr>
                </xsl:for-each>
              </table>
            </td>
          </tr>
        </table>
      </tr>

      <!--Security Details-->
      <tr class="trMain11">
        <table class="InnerMainTable" border="0">
          <tr class="trMain11">
            <td class="tdH2" >Security Details</td>
          </tr>
          <tr class="trMain11">
            <td colspan="2" class="tdH4">
              <table align="left" class="InnerSecurityTable">
                <tr>
                  <td class="tdSecurityHeaders" style="width:20%">Asset Class:</td>
                  <td class="tdSecurityValue" style="width:80%">
                    <xsl:value-of select="$assetTypeText" />
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </tr>

      <!--Order Details-->
      <tr> 
        <table class="InnerMainTable" border="0">
          <tr>
            <td class="tdH2" colspan="2">Order Details</td>
          </tr>
          <tr>
            <td class="tdInnerOrderDetailsTableValue" colspan="2" >
              <!--Replace this DIV with current template-->
              <div class="TemplateDiv" id="content">
                <xsl:value-of select="orderDetails/HTMLData" disable-output-escaping="yes"/>
              </div>
            </td>
          </tr>
        </table>
      </tr>
    </table>
  </xsl:template>

要转换的C#代码

Assembly asm = Assembly.GetExecutingAssembly();
Stream configStream = asm.GetManifestResourceStream(Xslt); //Fetching XSLT File Location from config
XmlTextReader configReader = new XmlTextReader(configStream);
myXslTrans.Load(configReader); //Reading XSLT File
StringBuilder sb = new StringBuilder();
MemoryStream inputStream = new MemoryStream(myXml); //this contains the embedded HTML Code ... orderDetails/HTMLData
XmlReader inputXmlReader = XmlTextReader.Create(inputStream);
MemoryStream memOutputStream = new MemoryStream();

//Perform Transformation
myXslTrans.Transform(inputXmlReader, new XsltArgumentList(), memOutputStream);
memOutputStream.Flush();
memOutputStream.Position = 0;
StreamReader reader = new StreamReader(memOutputStream);
sb.Append(reader.ReadToEnd());
MyWebBrowserControl.NavigateToString(sb.ToString()); //Displays the HTML Content

如何实现这一目标?

0 个答案:

没有答案