First I would like to discuss on how to insert c# scripting in xslt, which is sometimes very helpful specially when parsing involve, which is quite complicated in xslt code. The 2nd part of is how to render xslt with c# code in c#.
Part 1
1) On the style sheet element add the msxls namespace and c# code namespace, as show below.
<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform" row="http://tempuri.org/NewsLetterData.xsd" msxsl="urn:schemas-microsoft-com:xslt" prefixes="msxsl" code="Code"></xsl:stylesheet>
2) After the xslt element proceed with your c# code script as shown below. Add some assembly and assembly namespace which your code used.
<?xml:namespace prefix = msxsl /><msxsl:script language="C#" prefix="Code">
<msxsl:assembly name="System.Data"></msxsl:assembly>
<msxsl:using namespace="System.Text"></msxsl:using>
<msxsl:using namespace="System.IO"></msxsl:using>
</msxsl:script>
3) When c# code is ready you can easily call your code inside your xslt by specifying <code namespace declared>:<codename>.
<xsl:variable name="output" select="Code:YourCodeHere($parameter)" />
Rendering Xslt with c# code
No comments:
Post a Comment