您好,欢迎访问一九零五行业门户网

用XsltArgumentList实现xsl的参数调用

选择自 hstod 的 blog
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="high"/> <embed quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"> <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> </embed> </object> </xsl:template> </xsl:stylesheet>
xml文件
<?xml version="1.0" encoding="gb2312"?> <db> <l name="测试1" height="100" width="100" link="http://www.123.com" file="20056171345164340.gif" key="200561713451653143405" type="1" /> </db>
以上就是用xsltargumentlist实现xsl的参数调用的内容。
其它类似信息

推荐信息