By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,975 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,975 IT Pros & Developers. It's quick & easy.

XSL and VB.NET classes

P: n/a
I am creating a website for a client and I am using XSL for my email
templates and I have that parses the templates and creates an email. I have
a custom class called EmailAddress which has one parameter of type string
that is named email. In this class I have some private verification
functions for the address. Another class I have is MailingList. Here it has
2 private variables, and there cooresponding properties.

Private pEmail as EmailAddress
Private pHash as String

In the past pEmail was a string, but I decided to place all the email
verification functions in one class to make things easier. In my MailingList
class I have a function to send the email which will pass a hash table to the
email parser that works with the XSL.

Private Sub SendMailingListVerification()
Dim hashTbl As New Hashtable
hashTbl("ext:MailingList") = Me

System.Web.HttpContext.Current.Server.MapPath("~/public/templates/AddMailingList.xslt"), hashTbl)
End Sub

The EmailTemplate Class is as follows

Imports Microsoft.VisualBasic
Imports System.Collections
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath
Imports System.Text
Imports System.Net.Mail

Namespace BusinessLogic

Public Class EmailTemplate

Public Shared Sub SendEmailMessage(ByVal emailTo As String, ByVal
xslTemplate As String, ByVal dictionary As IDictionary)

Dim objXSLT As New XslCompiledTransform

Dim xmlDoc As New XmlDocument
xmlDoc.AppendChild(xmlDoc.CreateElement("DocumentR oot"))
Dim xPathNav As XPathNavigator = xmlDoc.CreateNavigator

Dim xslArg As New XsltArgumentList
If dictionary IsNot Nothing Then
For Each entry As DictionaryEntry In dictionary
xslArg.AddExtensionObject(entry.Key.ToString, entry.Value)
End If

Dim emlBuilder As New StringBuilder
Dim xmlWriter As New XmlTextWriter(New

objXSLT.Transform(xPathNav, xslArg, xmlWriter)

Dim subjText As String
Dim bodyText As String

Dim xEmailDoc As New XmlDocument
Dim titleNode As XmlNode = xEmailDoc.SelectSingleNode("//title")

subjText = titleNode.InnerText

Dim bodynode As XmlNode = xEmailDoc.SelectSingleNode("//body")

bodyText = bodynode.InnerXml
If bodyText.Length > 0 Then
bodyText = bodyText.Replace("&", "&")
End If

Dim oMail As New MailMessage(Configuration.SMTPSender, emailTo)
oMail.Subject = subjText
oMail.Body = bodyText
oMail.BodyEncoding = Encoding.UTF8
oMail.IsBodyHtml = True

Dim oSMTP As New SmtpClient(Configuration.SMTPServer)
oSMTP.Credentials = New
System.Net.NetworkCredential(Configuration.SMTPUse rName,
End Sub

End Class

End Namespace

And the XSL is:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
<xsl:template match="/">
<title>The Jim Wooters Campaign</title>
Thank you for your interest in the The Jim Wooters Campaign,
In order for you to receive emails from our mailing list, you must
first confirm your email address by clicking on the link below.<BR />
<xsl:attribute name="href"><xsl:value-of
select="MailingList:get_Email()" />&amp;validation=<xsl:value-of
select="MailingList:get_Hash()" />

select="MailingList:get_Email()" />&validation=<xsl:value-of
select="MailingList:get_Hash()" />
The Jim Wooters Campaign

This works when I have the email parameter from the MailingList class as a
string and not my custom EmailAddress class. Is there a way in XSL that I
can refer first to the MailingList class as that is what I am passing in my
hash table then to the EmailAddress variable.

In psudo code something like...

ml.Email.Address where email is a property from the mailing list class and
Address is the property from the EmailAddress class.

Basically I am wondering how if I have a class that contains another class I
can get XSL to use it without changing the parser functions all the time.
Jun 5 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.