I'm trying to wrap new lines in paragraphs without eliminating the HTML in the mixed node. I can get one or the other to work, but not both.
XML:
<root>
<mixed html="true">
line 1
<a href="http://google.com">line 2</a>
<em>line 3</em>
</mixed>
</root>
desired output:
<div>
<p>line 1</p>
<p><a href="http://google.com">line 2</a></p>
<p><em>line 3</em></p>
</div>
these templates match the HTML:
<xsl:template match="//*[@html]//*">
<xsl:element name="{name()}">
<xsl:apply-templates select="* | @* | text()"/>
</xsl:element>
</xsl:template>
<xsl:template match="//*[@html]//@*">
<xsl:attribute name="{name(.)}">
<xsl:copy-of select="."/>
</xsl:attribute>
</xsl:template>
these templates convert new lines to paragraphs:
<xsl:template name="nl2p">
<xsl:param name="input" />
<xsl:variable name="output">
<xsl:call-template name="newline-to-paragraph">
<xsl:with-param name="input">
<xsl:copy-of select="$input" />
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:copy-of select="$output" />
</xsl:template>
<!-- convert newline characters to <p></p> -->
<xsl:template name="newline-to-paragraph">
<xsl:param name="input" />
<xsl:variable name="output">
<xsl:choose>
<xsl:when test="contains($input, ' ')">
<xsl:if test="substring-before($input, ' ') != ''">
<xsl:element name="p"><xsl:copy-of select="substring-before($input, ' ')" /></xsl:element>
</xsl:if>
<xsl:call-template name="newline-to-paragraph">
<xsl:with-param name="input">
<xsl:copy-of select="substring-after($input, ' ')" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$input != ''">
<xsl:element name="p"><xsl:copy-of select="$input" /></xsl:element>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:copy-of select="$output" />
</xsl:template>
Is this possible? I realize the nl2p template runs string functions on the nodeset -- does this destroy the HTML? Can I preserve it or use a specific order of operations to achieve this result?
Thanks in advance.
Edit: I'm using XSLT 1.0