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

XML
XSL-FO 初学者教程:认识XSLFO
XSL-FO 初学者教程:XSL-FO 文档
XSL-FO初学者教程:XSL-FO 区域
XSL-FO 初学者教程:XSL-FO 输出和流
XML教程:XML DOM 访问节点
XML教程:XML DOM 节点信息
XML 和XSLT结合使你的网站设计浑然一体
XPath 新手入门教程:XPath 简介
XPath 初学者入门教程:XPath 节点
XML HttpRequst对象基础方法学习
XQuery 初学者入门教程:XQuery简介
XQuery 初学者入门教程:XQuery实例
jQuery入门简介
XML入门教程:XML DHTML 行为
XML入门教程:向XML文件存储数据
XML入门教程:服务器上的XML
XML入门教程:XML CDATA
XML入门教程:XML 解析器
XML入门教程:现实生活中的XML
XML入门教程:使用XSL显示XML

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 40 ::
收藏到网摘: 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>