How to remove extra spaces of element values in xslt
2 answers
If you want to strip a character or more, use a translation listing the character (s) as the second argument and an empty string as the third translate(., ' ', '')
eg.
<xsl:template match="sss">
<xsl:copy>
<xsl:value-of select="translate(normalize-space(), ' ', '')"/>
</xsl:copy>
</xsl:template>
+4
source to share
To get the result with all spaces removed, use the standard XPath function translate()
translate(., ' 

	', '')
No need to use normalize-space()
.
The pattern required to close this gap is simply :
<xsl:template match="sss/text()">
<xsl:value-of select="translate(., ' 

	', '')"/>
</xsl:template>
The full transformation also includes an identity rule, so if the XML document contains no elements sss
, they will be copied "as is":
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sss/text()">
<xsl:value-of select="translate(., ' 

	', '')"/>
</xsl:template>
</xsl:stylesheet>
0
source to share