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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change text value / with _

Status
Not open for further replies.

inarobis

IS-IT--Management
Apr 3, 2006
71
CH
Hello all,

My name is ina and I am newbie in xsl and I would like to know how can I change it

<Style>
<Strategy>
<Strategy_Style>Geo\Asia</Strategy_Style>
<Strategy_Style>Geo\America</Strategy_Style>
<Strategy_Style>Geo\Europe</Strategy_Style>
<Strategy_Style>Sector\America/cash</Strategy_Style>
</Strategy>
</Style>

I would like to have Sector\America_Cash

Any suggestions?

Ina
 
This can be done with slight variation of identity transformation. Like this.
[tt]
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="node()|@*|text()|comment()|processing-instruction()">
<xsl:if test="contains(text(),'America/cash')">
<xsl:copy>
<xsl:value-of select="translate(.,'/','_')" />
</xsl:copy>
</xsl:if>
<xsl:if test="not(contains(text(),'America/cash'))">
<xsl:copy>
<xsl:apply-templates select="node()|@*|text()|comment()|processing-instruction()" />
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
[/tt]
The conditional can be tighten to 'Sector\America/cash' or loosen to simply '/' depending on how generic the sample represents the true data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top