Use custom functions in xslt
1. the xml file remains unchanged.
2. the xslt file should declare a namespace with two types of references. For select and non-select statements, add {}. Note that ""
3. Declare a class at will
4 The transform function should use an AddExtensionObject of argumentlist and specify the Namespace above (it will be associated)
------------------- 1 -----------------
<? Xml version = "1.0" encoding = "UTF-8"?>
<Employees>
<Employee>
<FirstName> Pierre-Emmanuel </FirstName>
<LastName> Dautreppe </LastName>
</Employee>
</Employees>
------------------- 2 ----------------------
<? Xml version = "1.0" encoding = "UTF-8"?>
<Xsl: stylesheetversion = "1.0"
Xmlns: xsl = "http://www.w3.org/1999/XSL/Transform"
Xmlns: myUtils = "pda: MyUtils">
<Xsl: template match = "/Employees">
<Employees>
<Xsl: for-each select = "Employee">
<Employee>
<Xsl: value-of select = "myUtils: FormatName (FirstName, LastName)"/>
</Employee>
<Br> </br>
<A href = "{myUtils: GetLink ()} default. aspx"> abc.com </a>
</Xsl: for-each>
</Employees>
</Xsl: template>
</Xsl: stylesheet>
------------ 3 -----------------------------
Public class MyXslExtension
{
Public string FormatName (string firstName, string name)
{
Return name + "," + firstName;
}
Public string GetLink ()
{
Return "http://www.anypromo.com /";
}
}
---------- 4 ---------------------------------
Using targumentlist arguments = new using targumentlist ();
Arguments. AddExtensionObject ("pda: MyUtils", new MyXslExtension ());
StringWriter output = new StringWriter ();
Extends compiledtransform transform = new extends compiledtransform ();
Transform. Load (Server. MapPath ("a. xslt "));
Transform. Transform (Server. MapPath ("a. xml"), arguments, output );
Response. Write (output. ToString ());