C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Custom extention objects for XSLT transformation.


Posted Date: 23 Nov 2004    Resource Type: Articles    Category: .NET Framework
Author: Atal Bihari UpadhyayMember Level: Gold    
Rating: 1 out of 5Points: 7



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.





Responses

Author: Anand Dinkerrao More    08 Jun 2005Member 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.



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Convert 'HTML Emails' to 'Text Emails'
Previous Resource: Cohesion of Methods in .NET programming
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use