Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eliminate white spaces in XSL

Status
Not open for further replies.

elayildizer

Programmer
Jul 20, 2005
9
0
0
TR
Hi to all;

does anybody know how I can eliminate white spaces. For example;

For example in original xml document,there exists

<doc name="ela yil eliminate white spaces">

and I want to change it using XSL to

<doc name="elayileliminatewhitespaces">

Thanks
 
Maybe with a template like this:

Code:
	<xsl:template name="removeSpaces">
		<xsl:param name="text"/>
		<xsl:choose>
			<xsl:when test="contains($text, ' ')">
				<xsl:variable name="bufferBefore" select="substring-before($text, ' ')"/>
				<xsl:variable name="newBuffer" select="substring-after($text, ' ')"/>
				<xsl:value-of select="$bufferBefore"/>
				<xsl:call-template name="removeSpaces">
					<xsl:with-param name="text" select="$newBuffer"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

Gert
 
Great! Can you add the solution to this thread, so it will be usefull for future users as well.

Cheers!

Gert
 
hi;
this is the solution. This code eliminates the white spaces of the name attribute of a tag at the place the template called.

CODE:

<xsl:template name="ELIMINATE_WHITE">
<xsl:copy>
<xsl:variable name="var" select="translate(@name,' ','')"/>
</xsl:copy>
</xsl:template>

PS: I make use of the Jon's code in thread 'White Spaces in XSL' marked by me.

Cheers...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top