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!

white spaces in XSL 1

Status
Not open for further replies.

elayildizer

Programmer
Jul 20, 2005
9
0
0
TR
Hi newsgroup,
I'm looking for a way to replace all white spaces with a character ("_") in an attribute of an element with XSL...
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="ela_yil_eliminate_white_spaces">

I'll be glad if you can help me.
Thanks...
 
How about something like this:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@*">
    <xsl:attribute name="{name(.)}">
      <xsl:value-of select="translate(., ' ', '_')"/>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
Thanks Jon, that's it.

But now I have one more problem, do you know a specific function for eliminating 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 again...
 
You can use the same thing, but put <xsl:value-of select="translate(., ' ', '')"/>


Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top