Selectively preserving line breaks with XSLThttp://forums.asp.net/t/347715.aspx/1?Selectively+preserving+line+breaks+with+XSLTThu, 25 Sep 2003 18:54:52 -0400347715347715http://forums.asp.net/p/347715/347715.aspx/1?Selectively+preserving+line+breaks+with+XSLTSelectively preserving line breaks with XSLT I'm stumped. I'm building a forum and I've written <a href="http://dev.mboffin.com/mb-markup.xsd"> an XML schema</a> that defines what markup is allowed in the posts. The markup allowed is basically the following tags: b, u, i, sub, sup, acronym, abbr, link, list, item, code, strike, and quote. I've written two functions to handle what people write in their posts. First, I have a function that validates their post against the schema to ensure they haven't broken any markup rules. This function is used before their post is added into the database - i.e. when they post. The second function transforms the markup in their post into HTML using <a href="http://dev.mboffin.com/mb-markup.xsl">an XSL stylesheet</a>. For instance, link tags are converted to a tags, quote tags are converted to styled div's, etc. This function is used anytime a person's post is displayed on the site. The problem I'm running into is how to handle line breaks. When someone is writing their post, I want them to be able to just hit enter for the next line. It would seem ridiculous to make them write a br tag whenever they wanted a new line. But, when I convert their post into HTML, I want all line breaks to be converted to br's. There are a few ways I could do this. 1) I could do a Replace(strPost, vbCrLf, &quot;<br> &quot;) before I send the post off to the validation function, and of course add the br tag as a valid element in my schema. 2) I could do the same as 1, but <i>after</i> it's been run through the validator, so the br's make it into the database. 3) I could convert the line breaks to br's when I transform it into HTML. But, no matter how I go about it, I run into a problem that I know there must be an easy solution for. I run into the problem that they may write out a list, putting each item on a new line. This becomes a problem because br's aren't allowed inside the list tag, only item tags. (But br's would be allowed inside item tags.) Whether I do 1, 2, or 3, the problem is that someone writing this: Item 1 Item 2 Item 3 will end up with this, which is invalid: <br> Item 1<br> Item 2<br> Item 3<br> What should I do? How can I preserve the line breaks, but only in places where a <br> would be valid? 2003-09-25T04:33:12-04:00348375http://forums.asp.net/p/347715/348375.aspx/1?Re+Selectively+preserving+line+breaks+with+XSLTRe: Selectively preserving line breaks with XSLT I solved the problem. Basically, the line breaks aren't touched when it goes into the database. When it's pulled out of the database to be displayed, I replace all line breaks with <br> 's. Then, I transform it using the XSL stylesheet I've created. BUT, I just specify the following as the template for any <br> 's inside the tag: This just means that any <br> 's in the list tag should get transformed into nothing. 2003-09-25T18:52:59-04:00