joelkeepup wrote:
Quote:
|
im trying to output text, what is the correct media type in this case?
|
text/plain
Quote:
I can remove the escaping stuff, this was an html email and has been
adapted to send text.
>
The xml is:
"<?xml version=\"1.0\" encoding=\"utf-8\"?><InvitationMailTemplate
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=
\"http://www.w3.org/2001/XMLSchema\"><RecipientName>barney</
RecipientName><MailTitle>iBelong Invitations</
MailTitle><BodylinesCollection><Line>Joel has added you as a member of
the monday testolaa group.</Line></BodylinesCollection><LinkUrl>http://
localhost/Pages/Anonymous/SignIn.aspx?ReturnUrl=~/GroupHandler.ashx?
GroupId=44</LinkUrl><LinkUrlText>monday testolaa</
LinkUrlText><RemoveLinkUrl>http://localhost/Pages/Anonymous/
RejectInvitation.aspx?InvitationId=MgAxAA%3d%3d</
RemoveLinkUrl><RemoveLinkUrlText>here</
RemoveLinkUrlText><SecondLinkUrl>http://localhost/Pages/Anonymous/
SignUp.aspx?GroupId=44&PersistentTheme=iBelong </
SecondLinkUrl><SecondLinkUrlText>here</SecondLinkUrlText></
InvitationMailTemplate>"
>
>
I want it to output something like: (including newlines and
whitespace)
>
iBelong Invitations
>
Dear Barney,
>
Joel has added you as a member of the monday testolaa
>
To get started, click to visit the group now: http://localhost/Pages/Anonymous/Sig...shx?GroupId=44
....
|
Here is a sample stylesheet
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output media-type="text/plain" method="text" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:apply-templates select="InvitationMailTemplate"/>
</xsl:template>
<xsl:template match="InvitationMailTemplate">
<xsl:text>
</xsl:text>
<xsl:value-of select="MailTitle"/>
<xsl:text>
</xsl:text>
<xsl:text>Dear </xsl:text>
<xsl:value-of select="RecipientName"/>
<xsl:text>,</xsl:text>
<xsl:text>
</xsl:text>
<xsl:for-each select="BodylinesCollection/Line">
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:text>To get started, click to visit the group now:</xsl:text>
<xsl:text>
</xsl:text>
<xsl:value-of select="LinkUrl"/>
</xsl:template>
</xsl:stylesheet>
You could then run that as follows to get a string result:
XslCompiledTransform proc = new XslCompiledTransform();
proc.Load(@"..\..\XSLTFile1.xslt");
StringWriter result = new StringWriter();
proc.Transform(@"..\..\XMLFile1.xml", null, result);
string text = result.ToString();
result.Close();
Console.WriteLine("|{0}|", result);
which outputs
|
iBelong Invitations
Dear barney,
Joel has added you as a member of the monday testolaa group.
To get started, click to visit the group now:
http://localhost/Pages/Anonymous/SignIn.aspx?ReturnUrl=~/GroupHandler.ashx?GroupId=44|
The bars "|{0}|" in the Console.WriteLine are just there to show any
leading or trailing white space here for the post, you would obviously
not include them in the real application.
So wrap any literal text including line breaks into
<xsl:text></xsl:textand output values with xsl:value-of, then you
should have it. You don't need any memory streams to create a string as
the transformation result, a StringWriter suffices.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/