I am using a translate() function in a xslt script to remove unwanted string from a repeating element before rendering the output. While the translate function is doing its job, it is affecting a handful of these elements by removing more characters than it should and I can't for the life of me figure out why that is happening.
Here's an example XML document:
<?xml version="1.0" encoding="utf-8"?><books><book><title>Keep this text [remove this text]</title></book><book><title>Keep this text 2 [remove this text]</title></book><book><title>Keep this text 3 [remove this text]</title></book><book><title>Keep this text 4</title></book></books>
Here's a VERY basic example portion of a XSLT that tests for the [remove this text] string from the title element (this function is nested in a for-each loop):
<xsl:value-of select="translate(books/book/title, '[remove this text]', '')" />
This successfully removes the unwanted string and in most cases preserves the preceding text without issue. Unfortunately, in a handful of issues, the resultant output of the title element will be missing several characters (all white space is removed) and will look like "kpptt2" instead of "Keep this text 2". Does any one know why this might happen and/or produces flukes such as this example? Thank you!