XSL Textarea Collapse Problem

April 3rd, 2007

Using the PHP XSL functions I’ve been implementing a custom form markup language that decouples awkward form validation code from web forms. However I ran across a problem regarding text areas and the XML output method. Put simply, if the output method of your XSL Template is set to XML and you have a blank <textarea> tag, then it will collapse it to <textarea />.

As browsers don’t recognise this, it will cause the rest of the form HTML to run into the text area. I found another person who had the same problem, the suggested solutions were either to change the output method to “html” or to insert a <xsl:text> field containing a space to force a closing tag. There is a problem with each fix:

  1. Using the “html” output method won’t render your document properly formed xHTML.
  2. Using Firefox the placeholder space shows up in the text area.

In the end I used a hack that seemed to do the trick: inserting a <xsl:value-of select=”@unknown” /> tag pointing to an unknown attribute. This causes the PHP XSLT parser to generate an opening and closing text area tag, even if it has nothing in between. However I would expect there is a better way of doing this.

2 Responses to “XSL Textarea Collapse Problem”

  1. Non_E Says:
    June 18th, 2007 at 10:46 pm

    Sounds great, I will try it as I am rewriting my website. I had to use some posprocessing scripts to get rid of this annoying problem. Thanks

  2. Alex Says:
    June 19th, 2007 at 5:13 pm

    Yes, I hope it works. I thought it worked, but then I was faced with the same problem again. Roll on the next specification of XSLT I think.