zoukankan      html  css  js  c++  java
  • 如何让xslt样式表接受参数

    我们经常会有这样的需求:有多份数据,需要共享一份样式表来转换。他们的区别可能就在于顶部会有一些小的差异,那么如何解决这个事情呢?

    1. 在XSLT中定义参数

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        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></Table></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();
            }

        }
    }

  • 相关阅读:
    CLOSE_WAIT过大,致使tomcat停掉
    nginx安装
    前端知识点及面试题总结
    博客第一次
    二叉树的深度-python
    数字在排序数组中出现的次数-python
    两个链表的第一个公共节点-python
    自动生成接口自动化测试报告
    python实现四舍五入
    使用python的configparser操作.ini配置文件
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1488862.html
Copyright © 2011-2022 走看看