This is my problem: The code snippet below (inside the <xsl:choose>
) does not reliably strip <p>
, <div>
or <br>
tags out of a string using a combination of the substring-before()
and substring()
functions.
The string I'm trying to format is an attribute of a SharePoint SPS 2003 list item - text inputted via a rich text editor. What I ideally need is a catch-all <xsl:when>
test that will always just grab the text within the string before a line break (effectively the first paragraph). I thought that:
<xsl:when test="contains(Story, '
')='True'">
Would do that, but it doesn't always work as although the rich text editor inserts <br>
and <p>
tags, it appears that these are not always represented by the 

value.
Please help - this is driving me nuts. Code:
<xsl:choose>
<xsl:when test="contains(Story, '
')">
<div>PTAG_OPEN_OR_BR<xsl:value-of select="substring-before(Story,'
')" disable-output-escaping="yes"/></div>
</xsl:when>
<xsl:when test="contains(Story, '
') and contains(Story, 'div>')">
<div>DTAG<xsl:value-of select="substring-before(substring-after(substring-before(Story, '/div>'), 'div>'),'
')" disable-output-escaping="yes"/></div>
</xsl:when>
<xsl:when test="contains(Story, '
')!='True' and contains(Story, 'br>')">
<div>BRTAG<xsl:value-of select="substring(Story, 1, string-length(substring-before(Story, 'br>')-1))" disable-output-escaping="yes"/></div>
</xsl:when>
<xsl:otherwise>
<div>NO_TAG<xsl:value-of select="substring(Story, 1, 150)" disable-output-escaping="yes"/></div>
</xsl:otherwise>
</xsl:choose>
EDIT:
Will try out your suggestion Tomalak. Thank you.
EDIT: 12/11/09
Only just had chance to try this out. Thanks for your help Tomalak - I have one question in regard to rendering this as html rather than xml. when I call the template removeMarkup, I get the following error message:
Exception: System.Xml.XmlException Message: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 120, position 58.
I'm not sure but I believe that this is because you can't have xslt tags inside other attributes? Is there any way around this?
Thanks Tim