Email Templates using ASP.Net 4.0 and XSLT Stylesheets

Posted on 2012-09-17
Last Modified: 2012-09-20
I have need to create some HTML email templates and then access those templates via 4.0 code -- I also need to inject data into those templates with loops and fun stuff like that...

So, I found the following websites that talk about using an XML file to format data using XSLT and output HTML:

All of those websites use a static XML file that get styled with the XSLT and output to HTML.

The thing I am struggling with is whether or not I HAVE to first create an XML file containing my data then style it with XSLT -- or -- if I can just 'style' my data with the XSLT without first creating an XML-Based version of my data.

Any help is appreciated.
Question by:jsmithr
    1 Comment

    Accepted Solution

    I was able to figure this out by paying closer attention to the contents of the links I originally posted:

                ' Definte XML and XML Nodes
                Dim xmlDoc As New XmlDocument
                Dim xmlRoot As XmlElement
                Dim xmlNode As XmlNode
                ' Dim xmlChild As XmlNode ' ### Not Needed
                ' Define XML Structure
                ' @@@ These string builders should be included in a class in the Helper Class Library
                Dim sbFeedBackXMLStructure As New StringBuilder
                sbFeedBackXMLStructure.Append("<?xml version=""1.0"" encoding=""utf-8"" ?>")
                ' Set the values of the XML Nodes that will be used by XSLT
                xmlRoot = xmlDoc.DocumentElement
                xmlNode = xmlRoot.SelectSingleNode("/Root/Title")
                xmlNode.InnerText = ddlContactSubject.SelectedItem.Text
                xmlNode = xmlRoot.SelectSingleNode("/Root/SalesRepFullName")
                xmlNode.InnerText = objCustomerMaster.SalesRepName
                xmlNode = xmlRoot.SelectSingleNode("/Root/FullName")
                xmlNode.InnerText = objCustomerMaster.FullName
                xmlNode = xmlRoot.SelectSingleNode("/Root/UserName")
                xmlNode.InnerText = Context.User.Identity.Name
                xmlNode = xmlRoot.SelectSingleNode("/Root/CustomerNumber")
                xmlNode.InnerText = objCustomerMaster.CustomerNumber
                xmlNode = xmlRoot.SelectSingleNode("/Root/CompanyName")
                xmlNode.InnerText = objCustomerMaster.CompanyName
                xmlNode = xmlRoot.SelectSingleNode("/Root/EmailAddress")
                xmlNode.InnerText = objCustomerMaster.EmailAddress
                xmlNode = xmlRoot.SelectSingleNode("/Root/Message")
                xmlNode.InnerText = txbContactContent.Text
                ' Style with XSLT Template
                Dim xslDoc As New XslCompiledTransform
                Dim xslArgs As New XsltArgumentList
                Dim swWriter As New StringWriter
                ' Merge XSLT with XML
                ' ### Writer will hold resulted transformation
                xslDoc.Transform(xmlDoc, xslArgs, swWriter)
                Dim strGeneratedHTML As String = swWriter.ToString

    Open in new window

    So, no need to reply. I will request that this Question be closed.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now