• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

Email Templates using ASP.Net 4.0 and XSLT Stylesheets

I have need to create some HTML email templates and then access those templates via asp.net 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:

http://www.dirigodev.com/blog/your-first-xsl-transformation-in-aspnet-4/
http://www.codeproject.com/Articles/9603/Email-Template-using-XSLT-and-XSLTArgumentList
http://alekdavis.blogspot.com/2009/08/sending-html-based-email-from-net.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.
Jason
0
jsmithr
Asked:
jsmithr
1 Solution
 
jsmithrAuthor Commented:
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"" ?>")
            sbFeedBackXMLStructure.Append("<Root>")
            sbFeedBackXMLStructure.Append("<Title/>")
            sbFeedBackXMLStructure.Append("<SalesRepFullName/>")
            sbFeedBackXMLStructure.Append("<FullName/>")
            sbFeedBackXMLStructure.Append("<UserName/>")
            sbFeedBackXMLStructure.Append("<CustomerNumber/>")
            sbFeedBackXMLStructure.Append("<CompanyName/>")
            sbFeedBackXMLStructure.Append("<EmailAddress/>")
            sbFeedBackXMLStructure.Append("<Message/>")
            sbFeedBackXMLStructure.Append("</Root>")
            xmlDoc.LoadXml(sbFeedBackXMLStructure.ToString)

            ' 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
            xslDoc.Load(Server.MapPath("EmailTemplates\Feedback.xslt"))

            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.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now