I have an xml that has a node description:
<config>
<desc>A <b>first</b> sentence here. The second sentence with some link <a href="myurl">The link</a>. The <u>third</u> one.</desc>
</config>
I am trying to separate sentences using a period as a separator, but at the same time storing the output HTML tags in HTML. I am still a template that breaks the description, but HTML tags are lost due to the normalize-space and substring-before functions. My current template is listed below:
<xsl:template name="output-tokens">
<xsl:param name="sourceText" />
<xsl:variable name="newlist" select="concat(normalize-space($sourceText), ' ')" />
<xsl:choose>
<xsl:when test ="contains($newlist, '.')">
<xsl:variable name="first" select="substring-before($newlist, '.')" />
<xsl:variable name="remaining" select="substring-after($newlist, '.')" />
<xsl:if test="normalize-space($first)!='.' and normalize-space($first)!=''">
<p><xsl:value-of select="normalize-space($first)" />.</p>
</xsl:if>
<xsl:if test="$remaining">
<xsl:call-template name="output-tokens">
<xsl:with-param name="sourceText" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:if test="normalize-space($sourceText)!=''">
<xsl:value-of select="normalize-space($sourceText)" />.
</xsl:if>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
and I use it as follows:
<xsl:template match="config">
<xsl:call-template name="output-tokens">
<xsl:with-param name="sourceText" select="desc" />
</xsl:call-template>
</xsl:template>
Expected Result:
<p>A <b>first</b> sentence here.</p>
<p>The second sentence with some link <a href="myurl">The link</a>.</p>
<p>The <u>third</u> one.</p>
source
share