My XML is being generated from a web form and some users are inserting line breaks and characters that being converted to line breaks \n
and broken entities, like &
I'm using some variables to convert and remove bad characters, but I don't know how to strip out these types of characters.
Here's the method I'm using to convert or strip out other bad characters. Let me know if you need to see the entire XSL. …
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz_aaea'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ äãêÂ.,'" />
<xsl:variable name="linebreaks" select="'\n'" />
<xsl:variable name="nolinebreaks" select="' '" />
…
<xsl:value-of select="translate(Surname, $uppercase, $smallcase)"/>
<xsl:value-of select="translate(normalize-space(Office_photos), $linebreaks, $nolinebreaks)"/>
The text in the XML contains content like this:
<Office_photos>bn_1.jpg: Showing a little Red Sox Pride! \nLeft to right:
Tessa Michelle Summers, \nJulie Gross, Alexis Drzewiecki</Office_photos>
I'm trying to get rid of the \n
character inside the data
As Lingamurthy CS explains in the comments
\n
is not treated as a single character in XML. It is simply parsed into two characters without any special handling.If this is literally want you want to change though, then in XSLT 1.0 you will need to use a recursive template to replace the text (XSLT 2.0 has a replace function, XSLT 1.0 doesn't).
A quick search on Stackoverflow finds one such template at XSLT string replace
To call this, instead of doing this....
You would just do this
Try this XSLT
(Credit to Mark Elliot who created the replace template)