国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET XML/XSL Transforms(轉(zhuǎn)載www.aspalliance.com)

2024-07-10 12:58:10
字體:
供稿:網(wǎng)友
transforming an xml document using xsl/t and outputting the results to the browser is a fairly simple task in asp.net. the following user control demonstrates the ease with which this can be accomplished. this user control has a parameter for the xml source(xmlsource), and a parameter for the xsl source(xslsource). when placing this user control on a page, simply specify both values (using relative paths, since they are server.mappath'ed within the user control) and you're done! the transformed result will be output to response.output and sent to the user's browser. you can use this to create a two line aspx file that simply uses this user control to render its output. by using output and/or fragment caching, you can ensure that the cpu load required to transform the xml is minimized.

<%@ control language="c#" %>
<%@ import namespace="system.xml" %>
<%@ import namespace="system.xml.xsl" %>
<%@ import namespace="system.xml.xpath" %>
<script runat="server" language="c#">
public string xmlsource, xslsource;
void page_load(){
    xmldocument docxml = new xmldocument();
    docxml.load(server.mappath(xmlsource));
    xsltransform docxsl = new xsltransform();
    docxsl.load(server.mappath(xslsource));
    docxsl.transform(docxml,null,response.output);
//    chapter.text = docxml.transformnode(docxsl);
}
</script>

an example of a page using this user control, output caching for 1 minute:

<%@page%>
<%@ register tagprefix="authors" tagname="chapters" src="/controls/chapters.ascx"%>
<%@ outputcache duration="60" varybyparam="none" %>
<authors:chapters id="chapters" runat="server"
    xmlsource="chapter.xml" xslsource="chapter.xsl" />

to test this out, you can use the following two files:

chapter.xml
<chapter>
    <!-- chapter name -->
    <name>chapter name</name>
    
    <!-- author -->
    <author>
        <name>steven smith</name>
        <email>[email protected]</email>
        <website>http://aspalliance.com/stevesmith/</website>
    </author>
    
    <!-- examples from chapter -->
    <examples>
    
        <example>
            <!-- the number from the book, e.g. 2.3 -->
            <reference>2.1</reference>
            
            <!-- link to working example -->
            <demo>
                <url>hellovb.asp</url>
                <link_text>hellovb.asp</link_text>
            </demo>
            
            <!-- link to source code -->
            <source>
                <url>hellovb.txt</url>
                <link_text>hellovb.asp source</link_text>
            </source>
            
            <!-- description of the example -->
            <description>hello world using classic asp.</description>
        </example>
        
    </examples>

</chapter>


chapter.xsl
<?xml version="1.0" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">

<xsl:output method="xml" />

<xsl:template match="/">
    <p>
   <xsl:apply-templates select="chapter" />
   </p>
</xsl:template>

<xsl:template match="/chapter" >
    <b><xsl:value-of select="name"/></b>
   <br/>
   by <xsl:apply-templates select="author" />
   <br/><br/>
   <xsl:apply-templates select="examples" />
</xsl:template>

<xsl:template match="author" >
    <i><xsl:value-of select="name"/></i>
</xsl:template>

<xsl:template match="examples" >
    <table bgcolor="#000033">
        <tr bgcolor="#ccccff">
            <th>reference</th>
            <th>demo</th>
            <th>source</th>
            <th>description</th>
        </tr>
        <xsl:apply-templates select="example" />
    </table>
</xsl:template>

<xsl:template match="example" >
    <tr bgcolor="#dddddd">
        <td><xsl:value-of select="reference"/></td>
        <td>
            <a>
                <xsl:attribute name="href">
                    <xsl:value-of select="demo/url"/>
                </xsl:attribute>
                <xsl:value-of select="demo/link_text"/>
            </a>
        </td>
        <td>
            <a>
                <xsl:attribute name="href">
                    <xsl:value-of select="source/url"/>
                </xsl:attribute>
                <xsl:value-of select="source/link_text"/>
            </a>
        </td>
        <td><xsl:value-of select="description"/></td>
    </tr>
</xsl:template>



</xsl:transform>
,歡迎訪問網(wǎng)頁設(shè)計(jì)愛好者web開發(fā)。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 彭山县| 乃东县| 张北县| 句容市| 任丘市| 黎川县| 九龙城区| 南江县| 呼玛县| 西乌珠穆沁旗| 邵武市| 闽侯县| 襄垣县| 凤阳县| 古浪县| 临朐县| 灵璧县| 浦东新区| 天峻县| 波密县| 闽侯县| 抚顺市| 临沧市| 金门县| 义马市| 勃利县| 凯里市| 永昌县| 玛纳斯县| 岳阳县| 宣恩县| 新安县| 栾川县| 鸡东县| 克拉玛依市| 容城县| 龙陵县| 德昌县| 水城县| 从化市| 水富县|