当前位置: 首页 > 图文教程 > XML家族 > XML > 用XsltArgumentList实现xsl的参数调用

XML
XML入门教程:使用CSS显示XML
XML入门教程:XML 浏览器支持
WEB中基于XMLHTTP的简单实例分析
基于AJAX技术实现Struts校验框架
Java中四种XML解析技术之不完全测试
高手简论:说说标签切换应用原则
使用Ajax时的十个常犯的错误
ajax代理程序自动判断字符编码
高效交换XML文档
读取XML为行记录
如何建立一个 XML 的开发环境
十分钟学会 xajax
基于AJAX技术提高搜索引擎排名
XML时代我们拥有.Net
更正用AJAX实现IE TREE无刷新取值的方法
利用XSLT来换XML的根
开发保留标准的浏览器功能的AJAX应用
用XML+VBS在ASP中实现报表的打印
建立MS XML 测试环境
XML入门精解之文件格式定义

XML 中的 用XsltArgumentList实现xsl的参数调用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 37 ::
收藏到网摘: n/a


    XmlDocument XmlDoc=new XmlDocument();
    XmlDoc.Load(strFilePath);

    XslTransform xslt = new XslTransform();
    xslt.Load(strXslPath);

    XsltArgumentList xslArg = new XsltArgumentList();
    xslArg.AddParam("Key1", "",IXPath);
    xslArg.AddParam("Path", "",strPath);

    StringBuilder sb = new StringBuilder("");
    StringWriter sw = new StringWriter(sb);
    XmlTextWriter writer = new XmlTextWriter(sw);
    xslt.Transform(XmlDoc,xslArg,writer,null);
    writer.Close();
    HXML.InnerHtml=sb.ToString();

这是xsl文件


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:param name="Key1"/>
 <xsl:param name="Path"/>
 <xsl:template match="/">
  <xsl:apply-templates select="/DB/L[@Key=$Key1]" />
 </xsl:template>
 
 <xsl:template  match="L[@Type='1']">
  <a target="_blank">
   <xsl:attribute name="href"><xsl:value-of select="@Link" /></xsl:attribute>
   <img border="0">
    <xsl:attribute name="width"><xsl:value-of select="@width" /></xsl:attribute>
    <xsl:attribute name="height"><xsl:value-of select="@height" /></xsl:attribute>   
    <xsl:attribute name="src"><xsl:value-of select="$Path" />Res/AD/<xsl:value-of select="@File" /></xsl:attribute>
   </img>  
  </a>
 </xsl:template>

<xsl:template  match="L[@Type='2']">
   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" >
    <xsl:attribute name="width"><xsl:value-of select="@width" /></xsl:attribute>
    <xsl:attribute name="height"><xsl:value-of select="@height" /></xsl:attribute>   
    <param name="movie"><xsl:attribute name="value"><xsl:value-of select="$Path" />Res/AD/<xsl:value-of select="@File" /></xsl:attribute></param>
    <param name="quality" value="http://www.ruanchen.com/"BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">

<?xml version="1.0" encoding="GB2312"?>
<DB>
  <L Name="测试1" height="100" width="100" Link="http://www.ruanchen.com" File="20056171345164340.gif" Key="200561713451653143405" Type="1" />
</DB>