This project is read-only.

StripHTML for specific tags

Feb 17, 2011 at 10:44 PM

Hi.

Having some issues with modifying Strip HTML to remove specific tags. In SPD2007 the below template errors with 'XSLT transform failed : 0x8007000e : Not enough storage is available to complete this operation.'

<xsl:template name="StripHTML">
  <xsl:param name="HTMLText" />
  <xsl:choose>
    <xsl:when test="contains($HTMLText, '&lt;a')">
      <xsl:call-template name="StripHTML">
        <xsl:with-param name="HTMLText"
        select="concat(substring-before($HTMLText, '&lt;a'), substring-after($HTMLText, '&gt;'))" />
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="contains($HTMLText, '&lt;/a')">
      <xsl:call-template name="StripHTML">
        <xsl:with-param name="HTMLText"
        select="concat(substring-before($HTMLText, '&lt;/a'), substring-after($HTMLText, '&gt;'))" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$HTMLText"
      disable-output-escaping="yes" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

The problem seems to be with the substring-before in the concat, '&lt;' is fine, '&lt;a' breaks.

I guess I'm missing something, but not sure what. Any help would be appreciated.

Thanks,

Dan.

Coordinator
Feb 18, 2011 at 3:41 AM

Dan:

Thanks for reposting here. I want to support the stuff that I've put out there, and to do that more effectively I'm hoping to get a good level of traffic here in the Discussions like I have over at SPServices.

What's happening in your template above is that you're getting stuck in an infinite loop, thus the "Not enough storage..." error.

What you haven't explained clearly in either of your posts is what you're trying to accomplish. Are you trying to remove only links or leave only links? I was going to figure out the answer to both questions, but I think I'll save myself some time and wait for the answer!

M.

Feb 18, 2011 at 3:50 AM

Cheers Marc,

I was using the above to see if I can remove only links... we're looking at stripping out some of the markup generated by the rich html editor and was using the above as a test.

I had originally thought that a infinite loop was the cause of the error but i tested by putting in a deliberate loop and got a different error in SPD.

Funny thing is I've used your template before to do exactly the same thing but don't I no longer have access to the files...

Thanks,

Dan.

Coordinator
Feb 18, 2011 at 5:10 AM

Dan:

What you're trying to do will be more complicated because there will usually still be ">"s prior to the "<a"s. So the template will need to be more complicated to figure that out.

M.

Feb 23, 2011 at 10:49 PM

Ah. Right you are. This is my recursive block which seems to work;

 

<xsl:when test="contains($HTMLText, '&lt;div')">
	<xsl:call-template name="StripHTML">
		<xsl:with-param name="HTMLText" select="concat(substring-before($HTMLText, '&lt;div'),substring-after(substring-after($HTMLText,'&lt;div'),'&gt;'))"/>
	</xsl:call-template>
</xsl:when>
<xsl:when test="contains($HTMLText, '&lt;/div')">
	<xsl:call-template name="StripHTML">
		<xsl:with-param name="HTMLText" select="concat(substring-before($HTMLText,'&lt;/div'),substring-after(substring-after($HTMLText, '&lt;/div'),'&gt;'))"/>
	</xsl:call-template>
</xsl:when>

Thnks.

 

 

Coordinator
Feb 24, 2011 at 1:34 AM

Great. Glad you got it. I wasn't sure exactly what you were aiming at.

M.