I am going to demonstrate how you can use custom extensions objects in for xslt transformation.
We can use custom extension object to leverage the power of .net framework library in our style sheet to drastically reduce the size of style sheet and also increase overall performance of the system. Note: Microsoft recommends that you should avoid using inline script blocks. You can use extension objects to implement custom routines when you design portable XSLT style sheets. Here is how it is done:
Step 1. Define a custom class as:
Public Class DateConvertor Public Function GetDateTime(ByVal data As String, ByVal format As String) As String Dim dt As DateTime = DateTime.Parse(data) Return dt.ToString(format) End Function End Class
Step 2 Add the class to style sheet as xslt extension object:
Dim objDateConvertor As DateConvertor = New DateConvertor Dim args As XsltArgumentList = New XsltArgumentList args.AddExtensionObject("urn:csc-date", objDateConvertor)
Step 3 Pass the extension object to transform method as: transform.Transform(doc, args, Response.OutputStream)
Step 4 Add the namespace in stylesheet as:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myObj="urn:csc-date">
Step 5 Call the function in stylesheet as:
<xsl:value-of select="myObj:GetDateTime($Date, 'dateformat')"/>
Pls let me know your input/feedback regarding this article.
|
| Author: Anand Dinkerrao More 08 Jun 2005 | Member Level: Bronze Points : 0 |
I am searching the same from last few days but i am not getting but this article is help full to me but i want more clarity about this and also include sample code for it. every thing is clear now but new com mer or fresher may have difficult to under stand.
Aand More.
|