losing newlines and whitespace on xslt processing

Hi, im trying to create a text email message using xslt template , the
transforms work great, but the newlines and whitespace in the xslt doc
are removed. Is there a setting somewhere I have missed:

My template is:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-
prefixes="msxsl">
  <xsl:output indent="yes" method="text" media-type="text/xml"
encoding="UTF-8" omit-xml-declaration="yes" />
  <xsl:template match="MailTemplate">

    <xsl:value-of select="MailTitle"/>
    <xsl:text disable-output-escaping="yes">
</xsl:text>
    Dear <xsl:value-of select="RecipientName"/>,

    <xsl:for-each select="BodylinesCollection/Line">
      <xsl:text disable-output-escaping="yes"></xsl:text>
      <xsl:text disable-output-escaping="yes"></xsl:text>
      <xsl:value-of select="."/>
    </xsl:for-each>
	  <xsl:text disable-output-escaping="yes"></xsl:text>
	  <xsl:value-of select="LinkUrl"/>
  </xsl:template>
</xsl:stylesheet>

My processing is:

      XmlSerializer xmlSerialization = new XmlSerializer(typeof
(MailTemplate));
      xmlSerialization.Serialize(textWriter, mailTemplate);
      memoryStream.Flush();
      memoryStream.Seek(0, SeekOrigin.Begin);
      XmlDocument input = new XmlDocument();
      input.Load(memoryStream);
      input.PreserveWhitespace = true;
      XsltArgumentList args = new XsltArgumentList();
      XslCompiledTransform xsl = new XslCompiledTransform();
      xsl.Load(GetInvitationTemplate(false));
      xsl.OutputSettings.NewLineOnAttributes = true;
      xsl.Transform(input, args, resultStream);
      resultStream.Flush();
      resultStream.Seek(0, SeekOrigin.Begin);
      plainText = reader.ReadToEnd();

I have tried playing with indent setting on xslt, no luck, I also
added:

input.PreserveWhitespace = true;
and
xsl.OutputSettings.NewLineOnAttributes = true;

none seem to have any effect.

thanks
Joel
0
taskowner (1)
10/1/2008 3:07:51 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
744 Views

Similar Articles

[PageSpeed] 46

joelkeepup wrote:
> Hi, im trying to create a text email message using xslt template , the
> transforms work great, but the newlines and whitespace in the xslt doc
> are removed. Is there a setting somewhere I have missed:
> 
> My template is:
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
> Transform"
>     xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-
> prefixes="msxsl">
>   <xsl:output indent="yes" method="text" media-type="text/xml"
> encoding="UTF-8" omit-xml-declaration="yes" />

What exactly do you want to create with the stylesheet? You choose 
output method="text" but then media-type="text/xml". That does not make 
any sense to me.

>   <xsl:template match="MailTemplate">
> 
>     <xsl:value-of select="MailTitle"/>
>     <xsl:text disable-output-escaping="yes">
> </xsl:text>

What is all the disable-output-escaping good for? With output 
method="text" that attribute has no meaning.

>     Dear <xsl:value-of select="RecipientName"/>,
> 
>     <xsl:for-each select="BodylinesCollection/Line">
>       <xsl:text disable-output-escaping="yes"></xsl:text>
>       <xsl:text disable-output-escaping="yes"></xsl:text>
>       <xsl:value-of select="."/>
>     </xsl:for-each>
> 	  <xsl:text disable-output-escaping="yes"></xsl:text>
> 	  <xsl:value-of select="LinkUrl"/>
>   </xsl:template>
> </xsl:stylesheet>

Please post the XML you want to process with the XSLT stylesheet and the 
text you want to create as the result, then I am sure we can come up 
with a stylesheet that creates that result.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
10/1/2008 3:42:32 PM
On Oct 1, 11:42=A0am, Martin Honnen <mahotr...@yahoo.de> wrote:
> joelkeepup wrote:
> > Hi, im trying to create a text email message using xslt template , the
> > transforms work great, but the newlines and whitespace in the xslt doc
> > are removed. Is there a setting somewhere I have missed:
>
> > My template is:
> > <?xml version=3D"1.0" encoding=3D"utf-8"?>
> > <xsl:stylesheet version=3D"1.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL=
/
> > Transform"
> > =A0 =A0 xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt" exclude-result-
> > prefixes=3D"msxsl">
> > =A0 <xsl:output indent=3D"yes" method=3D"text" media-type=3D"text/xml"
> > encoding=3D"UTF-8" omit-xml-declaration=3D"yes" />
>
> What exactly do you want to create with the stylesheet? You choose
> output method=3D"text" but then media-type=3D"text/xml". That does not ma=
ke
> any sense to me.
>
> > =A0 <xsl:template match=3D"MailTemplate">
>
> > =A0 =A0 <xsl:value-of select=3D"MailTitle"/>
> > =A0 =A0 <xsl:text disable-output-escaping=3D"yes">
> > </xsl:text>
>
> What is all the disable-output-escaping good for? With output
> method=3D"text" that attribute has no meaning.
>
> > =A0 =A0 Dear <xsl:value-of select=3D"RecipientName"/>,
>
> > =A0 =A0 <xsl:for-each select=3D"BodylinesCollection/Line">
> > =A0 =A0 =A0 <xsl:text disable-output-escaping=3D"yes"></xsl:text>
> > =A0 =A0 =A0 <xsl:text disable-output-escaping=3D"yes"></xsl:text>
> > =A0 =A0 =A0 <xsl:value-of select=3D"."/>
> > =A0 =A0 </xsl:for-each>
> > =A0 =A0 =A0<xsl:text disable-output-escaping=3D"yes"></xsl:text>
> > =A0 =A0 =A0<xsl:value-of select=3D"LinkUrl"/>
> > =A0 </xsl:template>
> > </xsl:stylesheet>
>
> Please post the XML you want to process with the XSLT stylesheet and the
> text you want to create as the result, then I am sure we can come up
> with a stylesheet that creates that result.
>
> --
>
> =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML
> =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/

HI Martin,

im trying to output text, what is the correct media type in this case?

I can remove the escaping stuff, this was an html email and has been
adapted to send text.

The xml is:
"<?xml version=3D\"1.0\" encoding=3D\"utf-8\"?><InvitationMailTemplate
xmlns:xsi=3D\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=3D
\"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=3D~/GroupHandler.ashx?
GroupId=3D44</LinkUrl><LinkUrlText>monday testolaa</
LinkUrlText><RemoveLinkUrl>http://localhost/Pages/Anonymous/
RejectInvitation.aspx?InvitationId=3DMgAxAA%3d%3d</
RemoveLinkUrl><RemoveLinkUrlText>here</
RemoveLinkUrlText><SecondLinkUrl>http://localhost/Pages/Anonymous/
SignUp.aspx?GroupId=3D44&amp;PersistentTheme=3DiBelong</
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/SignIn.aspx?ReturnUrl=3D~/GroupHandler.ash=
x?GroupId=3D44
.....

thanks
Joel
0
jnylund (3)
10/1/2008 4:07:04 PM
joelkeepup wrote:

> im trying to output text, what is the correct media type in this case?

text/plain

> 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&amp;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/SignIn.aspx?ReturnUrl=~/GroupHandler.ashx?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:text> and 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/
0
mahotrash (1777)
10/1/2008 4:43:37 PM
Reply:

Similar Artilces:

Outlook Client Is Losing Connection To Microsoft CRM While Online
Hi. I have Rollup 2 installed on both the Outlook Client and the server. On my laptop, I am running Win XP Pro with SP 2 and all the updates applied and Outlook 2003 with all the updates applied. I am noticing that I seem to be losing the connection to Microsoft CRM from the Outlook Client. Right after I boot my laptop I am able to access to Microsoft CRM from the Outlook Client for between 4 hours to a day. After that if I click on the Accounts, Contacts or Leads folders nothing seems to happen. I have waited up to 10 minutes after clicking and nothing. At this point I can still use...

How to transform XML by using XSLT
Hi I need to know how to transform a XML file by using a XSLT file. Consider the following XML file <?xml version="1.0" encoding="UTF-8" standalone="yes"?><LogFile><Dog TimeStamp="16.02.2004 10:04:48" ModifiedBy="Smith, Geoff"><NameOfDog>Fido</NameOfDog><Weight>10</Weight></Dog><Dog TimeStamp="16.02.2004 10:05:24" ModifiedBy="Scott, Al"><Color>Black</Color><Weight>12</Weight></Dog></LogFile By the magic of some XSLT file I want the follo...

Why do I lose contacts?
I enter a contact and a few days later (after a reboot) it's gone? Sometimes I show 80 contacts. Sometimes 1518? What is up with that? On Sun, 29 Nov 2009 22:12:01 -0800, Davis Straub wrote: > I enter a contact and a few days later (after a reboot) it's gone? > > Sometimes I show 80 contacts. Sometimes 1518? What is up with that? Not a clue. I ran Windows Live Mail without signing in to Windows Live Services for three, or four days. My Contacts list never changed, or disappeared during that time. It is, however, different than the Contacts list I normally see ...

Inherited process handle + process exit code
Hi I'm having one parent process which launches another process. This child process inherits process handle from its parent. Now I want to know the exit status of these two processes. Can I use GetExitCodeProcess() API here? or do I need to do something else, since now the hadles of both the processes is same and this API accepts handle only. Thanks Nishant Usually you use GetExitCodeProcess() on the process handle only after you know the process has stopped; it is poor style to poll using it. I don't know what you mean by "the handles of both the processes is the same". ...

Speed up the process of Account Modifier Tool
The tool account modifier takes to long to process for customers that have lots of transactions. The estimate time for one of our customers is 35 days (none stop). No customers can afford to be down for 35 days. Since this is a very old product and was never modified I strongly believe it should be re designed in order for the Partners to keep sellling this tool. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not se...

excel process in the background
I'm trying to find a way of updating the excel spreadsheet without the excel application coming up on the users PC. We are getting input from the WEB and using that input to run a model and capture the data in an excel spreadsheet. Then manipulate the spreadsheet and create a summary Word document that will be emailed to the user. Then the user will be emailed with the summary data from the excel document. The thing is that this will be running on some server and I don't want the excel spreadsheet or application to actually come up on the PC. How can I suppress the applicati...

Processing imported QIF w/MS Money 2004 Deluxe
I download a QIF format statement for a checking account and import it into MS$2004. All appears to go OK. When I go to the page to process the downloaded statement MS$2004 abruptly aborts with "An error has been encountered" message. I have run standard file repair on the file prior to import and no problems are found according to the log file. After the aborted attempt, doing a file repair will indicate that a problem was found with the internet options and was corrected. Attempting to use the repaired file I can not access the transactions in the file that the import was for....

SS#'s lose lose formatting in .csv
Hi, I have a user who is entering a list of ss numbers. She has to have them in this format: 024574882 712894748 First off, we can't get the leading 0 to stay, it just disappears. I have tried formatting the column as text, as numbers, as custom #########, and like '983474744. No matter what we do, after saving and opening it again, the leading 0's are gone and some number turn in exponential notations. Can someone please help?? This should be an easy fix, but it seems the formatting I put on this does not hold!! thanks in advance.....Bill Select the column Either cl...

Extracting XML data to be used in XSLT HTML output
Ok: I have done small level Xml stuff and am just now starting to understand some of the plumbing involved. I've done a lot of .NET programming for SQL Server, but little for Xml data stores. I am currently just interested in using the .xsl file that I have being applied to a source .xml file through ASP classic. Here's what I have: XSL file ---------------------------------------------------------------------------- --- <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output meth...

Discover Card processing
We are trying to select a credit/debit card merchant service. I've been in contact with Mercury Payment Systems, Citibank, etc. In addition to Visa, MC, and Amex, we would like to accept Discover card at our store. However, Citibank told me I needed to talk to Discover directly. When I did, they told me in a roundabout way that their payment processing software is not compatible with RMS. In order to accept Discover, we need to use Paymentech or Bank of America, and they would need to submit the payment information to Discover, which would take a lot more time to receive the paymen...

losing pictures
I had produced a 3 fold brochure and printed it successfully for months. Then one day 2 of the jpg files stopped printing. I have reloaded Publisher, done everything I can think of, but can not get those files to print on the office color printer. They will print on the Black and white. The brochure will print from someone else's computer!!!! if I save the file on a CD and print it from someone who has Publisher. I talked to Gateway and they said it was my problem, this is a new 2003 computer, with 2002 Publisher. Can anyone help Update your printer driver from the website of your prin...

Budget Process
I budgeted in the Bills & Deposit list a ONE TIME entry for $10,600 to arrive January 15, 2009!!!!!!!!!!!!!!!!!!!! Why do my budget reports duplicate the amount to be received, ALSO, in February? For the life of me, I cannot figure out February's budgeted expense...except it duplicated the January amount, type of deposit, etc!! How do I reduce my February budget? Nothing seems to work. Thanks, FLKulxhar ...

Lose Focus
Env: VC++6.00 I want a control on a Dialog to be losed focus after it is disabled by EnableWindow(FALSE). I don't care who will get the focus, so I don't want to use SetFocus(). Is there a way? TIA William >I want a control on a Dialog to be losed focus after it is disabled by >EnableWindow(FALSE). >I don't care who will get the focus, so I don't want to use SetFocus(). > >Is there a way? William, Try using CDialog::NextDlgCtrl or maybe PostMessage WM_NEXTDLGCTL to the dialog. Dave Thanks Dave. That is exactly what I want. William > Try using CDial...

how to avoid import timesheet in timesheet approval process
when the team member submitted timesheet to the timesheet manager and timesheet manager approved this timesheet and then team member go to My Tasks page and import timesheet and then submitted to the Project Manager. Is it possible that team member dont need to import timesheet . if timesheet manager approved timesheet then timesheet will go to project manager directly. how it is possible ? and what is the reason behind this to import timesheet and then send to the project manager. Sam -- No, this is not possible. The best you can do for your organization is to elimina...

Losing online passwords
Money 2001. Recently, when I connect to online services, the password for my Discover Card account is sometimes missing. The other online banks remember their passwords. I always re-enter it and check "remember passwords", but about every 6 times I log on, the Discover password is missing. I just recently installed XP. Can anyone explain? I have noticed the same problem on my 98SE Money 2004. Must be on Discover's end. "OhMarty" <ohmarty@tampabay.rr.com> wrote in message news:%23OVhbJ6KEHA.3292@TK2MSFTNGP11.phx.gbl... Money 2001. Recently, when I connect to o...

Use XSLT to add header text to CSV
Hello, I'm trying to convert an xml file to csv using xslt. I can get the data to write out to the csv. I want to put a line of text at the beginning of the csv file that describes the content of the file. How do I do this using xslt? Thanks! stephen.surina@ferc.gov wrote: > Hello, > > I'm trying to convert an xml file to csv using xslt. I can get the > data to write out to the csv. I want to put a line of text at the > beginning of the csv file that describes the content of the file. How > do I do this using xslt? In the template for the document root, ad...

Changing ISP / email address
My friend is about to change ISP and get a new email address. He doesn't use webmail only Outlook. He has many folders containing emails he wants to keep, and also all his contacts. Can someone please tell me, if he changes email address will all the folder contents and contact details remain in Outlook? Are they on his hardrive or not? Thanks! Outlook data is stored locally. If he uses the same data file all his information will be there. -- Russ Valentine "Alfa Mum" <Alfa Mum@discussions.microsoft.com> wrote in message news:54C0F148-C087-4A8A-A25C-A...

Where to locate or kill these process?
Reading from internet, to remove Tencent.Addressbar etc, I need to stop these process iehelp.dll/iehelp1.dll/iehelp2.dll // ssaddr.dll/ssaddr1.dll/ssaddr2.dll and tbhmain.dll. My question is where do I find these or stop these as I could not find these files as I couls not find them in Alt/Ctl/Delete >Processes. Apprecuate your prompt response as I know this is not the correct place to loo for answers. Thanks The items you quoted are not running processes, but filenames. They may well be associated with a process or application in memory - such as "Tencent Addressbar&...

MS-Access In-Process Excel OLE activated window size
Hi, In MS-Access 2003, I displayed an excel file inside the OLE in a access form. When activating the OLE the excel sheet is activated and its width & height cannot be controlled to specific values programmatically. I tried with CROP/ZOOM/STRETCH options, nothing works fine. Can you please help me in controlling the hatch frame size after activation for of In-Process frame. ...

Cancelled Apays still processing
About 6-8 weeks ago I cancelled two apay series for loans that had been paid in full. Money sent the cancellation notices to my bank and removed both series from my bill pay calendar. Just tonight I noticed that on 7/28 and 8/6 payments were sent, one to each Apay series recipient. These payments never showed in my future bills list; do not show in the bill calendar; and, when clicked on in the account register, give me no way to remove the series permanently. One payment is to a local credit union, so I have no fear I can get that money back easily. The other, though, was sent to a...

Sort by date [XSLT]
Is there a way to use <xsl:sort> to sort by date. Sample xml doc I want to perform sorting on --------------------------------------------- <Parent> <child> <date>10/10/2003</date> <displayText>The text that should be displayed</displayText> </child> <child> <date>9/10/2001</date> <displayText>The text that should be displayed</displayText> </child> <child> <date>1/10/2002</date> <displayText>The text that should be dis...

You will find that with a quartz watch, you will on average lose or gain up to one second per week. Compare that to a mechanical watch, which can potentially lose or gain up to one minute per week.
You will find that with a quartz watch, you will on average lose or gain up to one second per week. Compare that to a mechanical watch, which can potentially lose or gain up to one minute per week. It is obvious that quartz watches are much more accurate and reliable than a mechanical watch. What makes quartz so accurate is its extremely high oscillations of up to 32,768 cycles per second at・3校salereplicawatch.com ...

ONLY 1 email account getting processed
Even with more than email set up my Outlook 2002 only processes the first one on the list. The move up and down (the email account) list does not work either. Any one else had this problem? It used to work OK, cannot figure what could have changed. Mike Check your send/receive settings for each account. -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. "Mike F" <MikeF@discussions.microsoft.com> wrote in me...

Trapping losing commands
In our applications once in a while the commands don't get through to the SQL Server for different reasons. Since it is an automatic process there is nobody in the front end to rerun those command, and they are getting lost. The rezones for the lost could be: Time out, broken connections, Deadlocks ect. Is there a way SQL can trap these and replay them? Gal (Gal@discussions.microsoft.com) writes: > In our applications once in a while the commands don't get through to > the SQL Server for different reasons. Since it is an automatic process > there is nobody in th...

losing a toolbar
I'm trying to setup my default workbook/sheet. Everything is working so far, except I cannot get rid of the standard toolbar. It keeps coming back. I do I get it out of my default preferences? thanks! Hi there; Right click on any toolbar and unchech the checkbox for the toolbar you don't want to see anymore. Save the file, close Excel and the next time you start it, it must not be visible anymore. Mark. More Excel ? www.rosenkrantz.nl or contact@rosenkrantz.nl -------------------------------------------------------------------- "shank" <shank@tampabay.rr.c...