How to Make xslt style sheets accept parameters

Source: Internet
Author: User
Tags xsl xslt

How to Make xslt style sheets accept parameters

We often need to share a style sheet to convert multiple copies of data. Their difference may be that there are some small differences on the top. How can we solve this problem?

1. Define parameters in 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> <Body>
<H1>
<Xsl: value-of select = "$ Title"/>
</H1>
</Body>
</Html>
</Xsl: template>
</Xsl: stylesheet>

2. Pass a parameter in the client code.

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> ");
Extends compiledtransform tran = new extends compiledtransform ();
Tran. Load ("Test. xslt ");
Inclutargumentlist a = new inclutargumentlist ();
A. AddParam ("Title", string. Empty, "Chen xizhang's Report ");
FileStream stream = new FileStream ("Test.htm", FileMode. Create );
Tran. Transform (doc. CreateNavigator (), a, stream );
Stream. Close ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.