Using the normalize-space() function is not enough, as it leaves the middle spaces!
Here is a simple and complete solution:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:strip-space elements="*" /> <xsl:template match="math"> <img class="math"> <xsl:attribute name="src">http://latex.codecogs.com/gif.latex?<xsl:value-of select="translate(.,' 	 ', '')" /></xsl:attribute> </img> </xsl:template> </xsl:stylesheet>
When this conversion is applied to the provided XML document :
<math>\text{average} = \alpha \times \text{data} + (1-\alpha) \times \text{average}</math>
required, the correct result is obtained :
<img class="math" src="http://latex.codecogs.com/gif.latex?\text{average}=\alpha\times\text{data}+(1-\alpha)\times\text{average}" />
Please note :
Use the XPath 1.0 translate() function to remove all unwanted characters.
There is no need to use replace() here - it may not be possible to use, because it is only available in XPath 2.0.
source share