I have a xml file and an xslt file in my website project. When I run the site, I need to call a c# function from xslt and alter the values in xml file.... Given below is my xml file.... I need to add a text (say "Mr.") in front of every firstname through a c# code.... After adding, it should reflect in the xml file.... Also, as a next step, I need to add another node in the xml file (say age) through another c# function.... Please note that the c# function should be called from my xslt file.... Can anyone help me with a simple code for this????
<?xml version="1.0" encoding="utf-8" ?>
<root>
<employee>
<firstname>Kaushal</firstname>
<lastname>Parik</lastname>
</employee>
<employee>
<firstname>Abhishek</firstname>
<lastname>Swarnkar</lastname>
</employee>
</root>
Yes, you can call C# function from .xsl file. Please refer following code.
This is your input XML File:
Formatting function in a C# class is like this:
Apply following xsl:
And C# Functin to call Formatting function is like this:
And the out put is:
I have referred this link to answer your question.
Hope this will help you.
Please mark +1 if it is useful to you....
Add the XSL style sheet reference to your XML document, like this:
or use
XslTransform
class to transforms XML data using anXSLT
from .NET:Apply following .xslt:
Input is:
Out put is:
and C# function is like this:
Hope this will help you...