I have an XML that in one node has a bunch of text with several paragraphs. I need to replace the \n with </p><p>
the text section in all will have a <p>
at the start and a </p>
at the end in the XSLT definition.
I have tried this but it gives me an error in Saxon: Variable find_all has not been declared (or its declaration is not in scope)
<xsl:template match="/csv/row/col[17]">
<xsl:param name="find_all">
<xsl:value-of select="."/>
</xsl:param>
<xsl:param name="find_return">
<xsl:text>(.*)\n(.*)</xsl:text>
</xsl:param>
<xsl:param name="replace_return">
<xsl:text>$1</p><p>$2</xsl:text>
</xsl:param>
</xsl:template>
And later this:
<col name="Model descr.">
<content>
<xsl:text><p></xsl:text>
</content>
<content>
<xsl:value-of select="replace($find_all, $find_return, $replace_return)"/>
</content>
<content>
<xsl:text></p></xsl:text>
</content>
</col>
Whats's wrong here??
Thanks
Jan
You are taking the wrong approach here. For a start, from the snippets you have shown us, you have a template with parameters, but those parameters are local in scope to that template. If you are trying to use those parameters outside the template, they won't be accessible.
Additionally, the
replace
function works with strings, and you cannot use it to create new elements like<p>
. What you will create in your output is the escaped value of<p>
.A different approach to take is use the
tokenize
function, to split the text based on the line-break, and iterate over each item, wrapping it in a new<p>
tag.Try this XSLT