如何在XSLT中嵌入ASPX页面指令?

时间:2013-01-04 20:28:55

标签: asp.net xslt

我需要使用XSLT输出一个包含特殊ASP指令的aspx文件,如

<%@ Page Title="Squire" Language="C#" MasterPageFile="~/Site1.Master"  %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

如何使用XSLT实现这一目标?

以下样式表摘录是否嵌入了页面并且命令未执行?

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  <xsl:output method="text" cdata-section-elements="aspx" />
  <xsl:template match="/">
    <aspx>
      <![CDATA[<%@ Page="" Title="Top New York City (Manhattan) Plastic Surgeons" Language="C#" MasterPageFile="~/Site1.Master" %>
      <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">]]>
    </aspx>
    <xsl:apply-templates/>
    <aspx><![CDATA[</asp:Content>]]></aspx>
  </xsl:template>

  <xsl:template match="PlaceDetailsResponse">
    <div class="page">
      <div style="float:left; width:100%;">
        <img src="{//icon}" alt="type" style="float:left" ></img>
        <h1 style="float:left;">
          <xsl:value-of select="@ReportHeading"/>
        </h1>
        <img src="images/info-icon.jpg" alt="information" style="float:right;margin-right:2px; height: 32px;"></img>
        <div id="info"></div>
      </div>
      <![CDATA[
        <script type="text/javascript">
            <!--
                google_ad_client = "ca-pub-3982825388677642";
                /* MobileBottom */
                google_ad_slot = "3380596110";
                google_ad_width = 468;
                google_ad_height = 60;
                //-->
        </script>
        <script type="text/javascript"
          src  ="http://pagead2.googlesyndication.com/pagead/show_ads.js">
        </script>
      ]]>
    </div>

    <div style="font-size:smaller; clear:both; border-bottom:double silver; padding:5px;">
        Sort by: <a href="*" >Places Ranking</a><a href="*" style="margin-left:5px;" >Yelp Ranking</a>
    </div>
  </xsl:template>

<xsl:template match="PlaceDetailsResponse/result">

    ... a couple more templates follow
</xsl:template>

1 个答案:

答案 0 :(得分:0)

我认为你需要使用disable-output-escaping - 这样的事情:

<xsl:text disable-output-escaping="yes">&lt;%@ Page="" Title="Top New York City (Manhattan) Plastic Surgeons" Language="C#" MasterPageFile="~/Site1.Master" %&gt;</xsl:text>