正文

为样式表单传递参数 xslt2007-11-03 16:38:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/jixian/30723.html

分享到:

xml文件: <?xml version="1.0" encoding="utf-8" ?><order>  <book ISBN="10-861003-324">    <title>the handmaid's tale</title>    <price>19.95</price>  </book>  <cd ISBN="2-3631-4">    <title>americana</title>    <price>16.95</price>  </cd></order> xslt文件: <?xml version="1.0" encoding="UTF-8" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  <xsl:param name="date"/>  <xsl:template match="/">  <order>    <date>      <xsl:value-of select="$date"/>    </date>    <total>      <xsl:value-of select="sum(//price)"/>    </total>      </order>  </xsl:template></xsl:stylesheet>   主程序: using System;using System.Collections.Generic;using System.Text;using System.Xml;using System.Xml.Xsl;using System.Xml.XPath; namespace argumentlistxslt{    class Program    {        private static string inputfile = @"E:\c#\c#_windows程序设计\argumentlistxslt\argumentlistxslt\order.xml";        private static string stylefile = @"E:\c#\c#_windows程序设计\argumentlistxslt\argumentlistxslt\order.xslt";        private static string resultfile = @"E:\c#\c#_windows程序设计\argumentlistxslt\argumentlistxslt\currentorder.xml";         static void Main(string[] args)        {            XPathDocument inputdoc=new XPathDocument(inputfile);            XslCompiledTransform transformer=new XslCompiledTransform();            transformer.Load(stylefile);             //创建xsltargumentlist 参数            XsltArgumentList arglist=new XsltArgumentList();             DateTime rightnow=DateTime.Now;            arglist.AddParam("date","",rightnow.ToString());  //中间“” 表示默认命名空间            XmlTextWriter xtw=new XmlTextWriter(resultfile,null);            transformer.Transform(inputdoc,arglist,xtw);            xtw.Close();                    }    }}  

阅读(2809) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册