G
Guest
I am working on a website for a client and one of their requirements was to
have a mailing list. I decided to XSLT to transform "templates" to HTML so
that editing was very easy and less time consuming. I keep getting the
following error when I submit my email to their site.
System.Xml.Xsl.XslTransformException: Cannot find the script or external
object that implements prefix 'ext:MailingList'. at
System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String
name, String namespaceUri, IList`1[] args) at (XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at Root(XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at
System.Xml.Xsl.ExecuteDelegate.Invoke(XmlQueryRuntime runtime) at
System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver
dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at
System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver
dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean
closeWriter) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable
contextDocument, XmlResolver dataSources, XsltArgumentList argumentList,
XmlWriter results) at
System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input,
XsltArgumentList arguments, XmlWriter results) at
BusinessLogic.EmailTemplate.SendEmailMessage(String emailTo, String
xslTemplate, IDictionary dictionary) at
BusinessLogic.MailingList.SendMailingListVerification() at
BusinessLogic.MailingList.Add() at _Default.cmdSubmitEmail_Click(Object
sender, ImageClickEventArgs e)
at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String
name, String namespaceUri, IList`1[] args) at (XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at Root(XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at
System.Xml.Xsl.ExecuteDelegate.Invoke(XmlQueryRuntime runtime) at
System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver
dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at
System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver
dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean
closeWriter) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable
contextDocument, XmlResolver dataSources, XsltArgumentList argumentList,
XmlWriter results) at
System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input,
XsltArgumentList arguments, XmlWriter results) at
BusinessLogic.EmailTemplate.SendEmailMessage(String emailTo, String
xslTemplate, IDictionary dictionary) at
BusinessLogic.MailingList.SendMailingListVerification() at
BusinessLogic.MailingList.Add() at _Default.cmdSubmitEmail_Click(Object
sender, ImageClickEventArgs e)
Here is my XSLT file:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:MailingList="ext:MailingList">
<xsl:template match="/">
<html>
<head>
<title>The SomeSite Campaign</title>
</head>
<body>
<P>
Thank you for your interest in the The SomeSite Campaign,
</P>
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 />
<a>
<xsl:attribute name="href">
http://www.somesite.com/subscriptions/ConfirmMailing.aspx?email=<xsl:value-of
select="MailingList:Email()" />&validation=
</xsl:attribute>http://www.SomeSite.com/subscriptions/ConfirmMailing.aspx?email=<xsl:value-of select="MailingList:Email()" />&validation=
</a>
<P>
Regards,
The SomeSite Campaign
</P>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
If I take out <xsl:value-of select="MailingList:Email()" /> statements an
email is generated and sent, but it just contains HTML. Here is my mailing
list class in which there is a email address and verification hash.
Imports Microsoft.VisualBasic
Namespace BusinessLogic
Public Class MailingList
Inherits BusinessLogic.DataAccessBase
Private pEmail As String
Private pHash As String
Public Property Email() As String
Get
Return pEmail
End Get
Set(ByVal value As String)
If Validation.ValidateEmail(value) = False Then Throw New
Exception(Resources.StringResources.EmailAddressInvalidFormat)
pEmail = value
End Set
End Property
Public Property Hash() As String
Get
Return pHash
End Get
Set(ByVal value As String)
pHash = value
End Set
End Property
Public Sub New(ByVal email As String, ByVal hash As String)
Me.Email = email
Me.Hash = hash
End Sub
Public Sub New()
End Sub
''' <summary>
''' Adds a new email address to the mailing list.
''' </summary>
Public Sub Add()
Dim dbConn As DataAccess.DataAccessBase =
DataAccess.DataAccessBaseHelper.GetDataAccessLayer
Dim pr As DataAccess.DataAccessBase.ProcedureResults
pr = dbConn.AddMailingList(pEmail, pHash)
Me.pErrorCode = pr.ErrorCode
Me.pRowCount = pr.RowCount
SendMailingListVerification()
End Sub
''' <summary>
''' Verifies an email address and marks it as valid.
''' </summary>
Public Sub Verify()
Dim dbConn As DataAccess.DataAccessBase =
DataAccess.DataAccessBaseHelper.GetDataAccessLayer
Dim pr As DataAccess.DataAccessBase.ProcedureResults
pr = dbConn.VerifyMailingList(pEmail, pHash)
Me.pErrorCode = pr.ErrorCode
Me.pRowCount = pr.RowCount
End Sub
''' <summary>
''' Removes an email address from the mailing list after validating
that it exists.
''' </summary>
Public Sub Delete()
Dim dbConn As DataAccess.DataAccessBase =
DataAccess.DataAccessBaseHelper.GetDataAccessLayer
Dim pr As DataAccess.DataAccessBase.ProcedureResults
pr = dbConn.DeleteMailingList(pEmail, pHash)
Me.pErrorCode = pr.ErrorCode
Me.pRowCount = pr.RowCount
End Sub
Private Sub SendMailingListVerification()
Dim hashTbl As New Hashtable
hashTbl("ext:List") = Me
EmailTemplate.SendEmailMessage(pEmail,
System.Web.HttpContext.Current.Server.MapPath("~/public/templates/AddMailingList.xslt"), hashTbl)
End Sub
End Class
End Namespace
Finally, here is my email class in which I am trying to insert my data into
the XSLT file so that I can send it.
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
objXSLT.Load(xslTemplate)
Dim xmlDoc As New XmlDocument
xmlDoc.AppendChild(xmlDoc.CreateElement("DocumentRoot"))
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)
Next
End If
Dim emlBuilder As New StringBuilder
Dim xmlWriter As New XmlTextWriter(New
System.IO.StringWriter(emlBuilder))
objXSLT.Transform(xPathNav, xslArg, xmlWriter)
Dim subjText As String
Dim bodyText As String
Dim xEmailDoc As New XmlDocument
xEmailDoc.LoadXml(emlBuilder.ToString)
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.SMTPUserName,
Configuration.SMTPPassword)
oSMTP.Send(oMail)
End Sub
End Class
End Namespace
I saw some examples of people using dictionary or hash table objects to
contain their data so that they only needed on so-called template parser. I
am trying to do the same as I will have 10-15 different templates when the
site is finished. Thanks for any help.
- Nick
have a mailing list. I decided to XSLT to transform "templates" to HTML so
that editing was very easy and less time consuming. I keep getting the
following error when I submit my email to their site.
System.Xml.Xsl.XslTransformException: Cannot find the script or external
object that implements prefix 'ext:MailingList'. at
System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String
name, String namespaceUri, IList`1[] args) at (XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at Root(XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at
System.Xml.Xsl.ExecuteDelegate.Invoke(XmlQueryRuntime runtime) at
System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver
dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at
System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver
dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean
closeWriter) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable
contextDocument, XmlResolver dataSources, XsltArgumentList argumentList,
XmlWriter results) at
System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input,
XsltArgumentList arguments, XmlWriter results) at
BusinessLogic.EmailTemplate.SendEmailMessage(String emailTo, String
xslTemplate, IDictionary dictionary) at
BusinessLogic.MailingList.SendMailingListVerification() at
BusinessLogic.MailingList.Add() at _Default.cmdSubmitEmail_Click(Object
sender, ImageClickEventArgs e)
at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String
name, String namespaceUri, IList`1[] args) at (XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at Root(XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime) at
System.Xml.Xsl.ExecuteDelegate.Invoke(XmlQueryRuntime runtime) at
System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver
dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at
System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver
dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean
closeWriter) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable
contextDocument, XmlResolver dataSources, XsltArgumentList argumentList,
XmlWriter results) at
System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input,
XsltArgumentList arguments, XmlWriter results) at
BusinessLogic.EmailTemplate.SendEmailMessage(String emailTo, String
xslTemplate, IDictionary dictionary) at
BusinessLogic.MailingList.SendMailingListVerification() at
BusinessLogic.MailingList.Add() at _Default.cmdSubmitEmail_Click(Object
sender, ImageClickEventArgs e)
Here is my XSLT file:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:MailingList="ext:MailingList">
<xsl:template match="/">
<html>
<head>
<title>The SomeSite Campaign</title>
</head>
<body>
<P>
Thank you for your interest in the The SomeSite Campaign,
</P>
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 />
<a>
<xsl:attribute name="href">
http://www.somesite.com/subscriptions/ConfirmMailing.aspx?email=<xsl:value-of
select="MailingList:Email()" />&validation=
</xsl:attribute>http://www.SomeSite.com/subscriptions/ConfirmMailing.aspx?email=<xsl:value-of select="MailingList:Email()" />&validation=
</a>
<P>
Regards,
The SomeSite Campaign
</P>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
If I take out <xsl:value-of select="MailingList:Email()" /> statements an
email is generated and sent, but it just contains HTML. Here is my mailing
list class in which there is a email address and verification hash.
Imports Microsoft.VisualBasic
Namespace BusinessLogic
Public Class MailingList
Inherits BusinessLogic.DataAccessBase
Private pEmail As String
Private pHash As String
Public Property Email() As String
Get
Return pEmail
End Get
Set(ByVal value As String)
If Validation.ValidateEmail(value) = False Then Throw New
Exception(Resources.StringResources.EmailAddressInvalidFormat)
pEmail = value
End Set
End Property
Public Property Hash() As String
Get
Return pHash
End Get
Set(ByVal value As String)
pHash = value
End Set
End Property
Public Sub New(ByVal email As String, ByVal hash As String)
Me.Email = email
Me.Hash = hash
End Sub
Public Sub New()
End Sub
''' <summary>
''' Adds a new email address to the mailing list.
''' </summary>
Public Sub Add()
Dim dbConn As DataAccess.DataAccessBase =
DataAccess.DataAccessBaseHelper.GetDataAccessLayer
Dim pr As DataAccess.DataAccessBase.ProcedureResults
pr = dbConn.AddMailingList(pEmail, pHash)
Me.pErrorCode = pr.ErrorCode
Me.pRowCount = pr.RowCount
SendMailingListVerification()
End Sub
''' <summary>
''' Verifies an email address and marks it as valid.
''' </summary>
Public Sub Verify()
Dim dbConn As DataAccess.DataAccessBase =
DataAccess.DataAccessBaseHelper.GetDataAccessLayer
Dim pr As DataAccess.DataAccessBase.ProcedureResults
pr = dbConn.VerifyMailingList(pEmail, pHash)
Me.pErrorCode = pr.ErrorCode
Me.pRowCount = pr.RowCount
End Sub
''' <summary>
''' Removes an email address from the mailing list after validating
that it exists.
''' </summary>
Public Sub Delete()
Dim dbConn As DataAccess.DataAccessBase =
DataAccess.DataAccessBaseHelper.GetDataAccessLayer
Dim pr As DataAccess.DataAccessBase.ProcedureResults
pr = dbConn.DeleteMailingList(pEmail, pHash)
Me.pErrorCode = pr.ErrorCode
Me.pRowCount = pr.RowCount
End Sub
Private Sub SendMailingListVerification()
Dim hashTbl As New Hashtable
hashTbl("ext:List") = Me
EmailTemplate.SendEmailMessage(pEmail,
System.Web.HttpContext.Current.Server.MapPath("~/public/templates/AddMailingList.xslt"), hashTbl)
End Sub
End Class
End Namespace
Finally, here is my email class in which I am trying to insert my data into
the XSLT file so that I can send it.
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
objXSLT.Load(xslTemplate)
Dim xmlDoc As New XmlDocument
xmlDoc.AppendChild(xmlDoc.CreateElement("DocumentRoot"))
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)
Next
End If
Dim emlBuilder As New StringBuilder
Dim xmlWriter As New XmlTextWriter(New
System.IO.StringWriter(emlBuilder))
objXSLT.Transform(xPathNav, xslArg, xmlWriter)
Dim subjText As String
Dim bodyText As String
Dim xEmailDoc As New XmlDocument
xEmailDoc.LoadXml(emlBuilder.ToString)
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.SMTPUserName,
Configuration.SMTPPassword)
oSMTP.Send(oMail)
End Sub
End Class
End Namespace
I saw some examples of people using dictionary or hash table objects to
contain their data so that they only needed on so-called template parser. I
am trying to do the same as I will have 10-15 different templates when the
site is finished. Thanks for any help.
- Nick