网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 如何让xslt样式表接受参数
内容
    我们经常会有这样的需求:有多份数据,需要共享一份样式表来转换。他们的 区别可能就在于顶部会有一些小的差异,那么如何解决这个事情呢?
    1. 在XSLT中定义参数
    <?xml version="1.0" encoding="utf- 8"?>
    <xsl:stylesheet version="1.0"  xmlns:xsl=""
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"  exclude-result-prefixes="msxsl"
    >
    <xsl:output method="xml"  indent="yes"/>
    <xsl:param name="Title"></xsl:param>
    <xsl:template match="/">
    <html>
    <head></head>
    <body>
    <h1>
    <xsl:value-of  select="$Title"/>
    </h1>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    2. 在客户端代码中传递一个参数过来
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Xml.Xsl;
    using System.Xml.XPath;
    using System.Xml;
    using System.IO;
    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    XmlDocument doc = new XmlDocument();
    doc.LoadXml ("<Tables><Table><Name>Orders</Name></T able></Tables>");
    XslCompiledTransform tran = new  XslCompiledTransform();
    tran.Load("Test.xslt");
    XsltArgumentList a = new XsltArgumentList ();
    a.AddParam("Title", string.Empty,  "陈希章的报告");
    FileStream stream = new FileStream ("Test.htm", FileMode.Create);
    tran.Transform(doc.CreateNavigator(), a,  stream);
    stream.Close();
    }
    }
    }
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/13 20:33:01