Given the XPath functions that you call that I donβt remember, having the luxury of MSXSL in my work, it looks like you are using an XPath 2-compatible processor.
If so, does XPath 2 have a replacement function (string, pattern, replacement) that takes a regular expression as the second parameter?
<xsl:value-of select="replace(string(.), ' (\s| )*', '</p><p>')" />
This can help get an Xml sample and find out which processor you plan to use.
From your initial example, it seems that all repeating paragraphs have only a prefix with a space. So, something like this small modification can clip crooks.
<xsl:when test="contains($text, $replace)"> <xsl:variable name="prefix" select="substring-before($text, $replace)" /> <xsl:choose> <xsl:when test="normalize-string($prefix)!=''"> <xsl:value-of select="$prefix"/> <xsl:value-of select="$by" disable-output-escaping="yes"/> </xsl:when> </xsl:choose> <xsl:call-template name="replace-text"> <xsl:with-param name="text" select="substring-after($text, $replace)"/> <xsl:with-param name="replace" select="$replace" /> <xsl:with-param name="by" select="$by" /> </xsl:call-template>
source share