SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have some XSLT when the value of Message is NULL the h2 transforms into a self closing tag. How can we stop this?

    <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl=""> 
    <xsl:output method="html" omit-xml-declaration="yes"/> 
    <xsl:template match="/">   <xsl:for-each select="Title"><h2><xsl:value-of select="Message"/> </h2>  </xsl:for-each>  </xsl:template> </xsl:stylesheet>
share|improve this question

Wrap the message in a choose block?

<xsl:for-each select="Title">
    <xsl:when test="string-length(Message) &gt; 0">
        <h2><xsl:value-of select="Message"/> </h2>
         //something to handle null or empty messages
share|improve this answer
Thanks for the response, that way would be rather verbose as I need to do it in a number of places. If I was going to do it with a test I would use this code <xsl:if test="Message != ''"> <h2><xsl:value-of select="Message"/> </h2></xsl:if> – Colin Murray Jun 7 '12 at 14:23
If you need to do it in a number of places, you could always make it a template and just call that template where needed. I went with choose so you could inject anything you wanted into the output like a generic message or any other html. – Eric Alexander Jun 7 '12 at 14:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.