I'm stumped. I'm building a forum and I've written
an XML schema 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 an XSL stylesheet. 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, "
") 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
after 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:
Item 1
Item 2
Item 3
What should I do? How can I preserve the line breaks, but only in places where a
would be valid?
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
's. Then, I transform it using the XSL stylesheet I've created. BUT, I just specify the following as the template for any
's inside the tag: This just means that any
's in the list tag should get transformed into nothing.
MBoffin
Member
60 Points
12 Posts
Selectively preserving line breaks with XSLT
Sep 25, 2003 04:33 AM|LINK
") 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 after 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:
Item 1
Item 2
Item 3
What should I do? How can I preserve the line breaks, but only in places where a
would be valid?
MBoffin
Member
60 Points
12 Posts
Re: Selectively preserving line breaks with XSLT
Sep 25, 2003 06:52 PM|LINK
's. Then, I transform it using the XSL stylesheet I've created. BUT, I just specify the following as the template for any
's inside the tag: This just means that any
's in the list tag should get transformed into nothing.